Ejemplo n.º 1
0
        public void RenameTemplateIDs()
        {
            if (this.VisualTreeRoot == null)
            {
                return;
            }
            SceneNodeIDHelper           sceneNodeIdHelper = new SceneNodeIDHelper(this.ViewModel, (SceneNode)this.VisualTreeRoot);
            Dictionary <string, string> renameTable       = new Dictionary <string, string>();

            foreach (SceneElement sceneElement in SceneElementHelper.GetElementTree((SceneElement)this.VisualTreeRoot))
            {
                string name = sceneElement.Name;
                if (name == null || name.StartsWith("~ChildID"))
                {
                    sceneNodeIdHelper.SetValidName((SceneNode)sceneElement, sceneElement.TargetType.Name);
                    if (name != null && sceneElement.Name != name)
                    {
                        renameTable.Add(name, sceneElement.Name);
                    }
                }
            }
            IStoryboardContainer storyboardContainer = (IStoryboardContainer)this;

            if (storyboardContainer == null)
            {
                return;
            }
            this.ViewModel.AnimationEditor.UpdateStoryboardOnElementRename(storyboardContainer, renameTable);
        }
Ejemplo n.º 2
0
 public override void Execute()
 {
     if (this.SceneViewModel.TextSelectionSet.IsActive)
     {
         this.SceneViewModel.TextSelectionSet.TextEditProxy.EditingElement.SelectAll();
     }
     else
     {
         SelectionManagerPerformanceHelper.MeasurePerformanceUntilPipelinePostSceneUpdate(this.SceneViewModel.DesignerContext.SelectionManager, PerformanceEvent.SelectElement);
         ISceneElementCollection elementCollection = (ISceneElementCollection) new SceneElementCollection();
         SceneElement            selectionRoot     = SelectAllCommand.GetSelectionRoot(this.SceneViewModel);
         if (selectionRoot != null)
         {
             foreach (SceneElement element in SceneElementHelper.GetElementTree(selectionRoot))
             {
                 if (this.IsSelectable(element, selectionRoot))
                 {
                     elementCollection.Add(element);
                 }
             }
         }
         this.SceneViewModel.ElementSelectionSet.SetSelection((ICollection <SceneElement>)elementCollection, (SceneElement)null);
         this.SceneViewModel.PathPartSelectionSet.Clear();
     }
 }
Ejemplo n.º 3
0
 SceneNode ITriggerContainer.ResolveTargetName(string name, SceneNode relativeSource)
 {
     if (string.IsNullOrEmpty(name))
     {
         return((SceneNode)(relativeSource as SceneElement ?? relativeSource.FindSceneNodeTypeAncestor <SceneElement>()));
     }
     return(SceneElementHelper.FindNode((SceneNode)this, name));
 }
Ejemplo n.º 4
0
 SceneNode ITriggerContainer.ResolveTargetName(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return((SceneNode)this);
     }
     return(SceneElementHelper.FindNode((SceneNode)this, name));
 }
Ejemplo n.º 5
0
 public override void Execute()
 {
     PerformanceUtility.StartPerformanceSequence(PerformanceEvent.Make3D);
     try
     {
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.SceneViewModel.ElementSelectionSet.PrimarySelection;
             using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoUnitName, false))
             {
                 ILayoutDesigner designerForChild = this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true);
                 Rect            childRect        = designerForChild.GetChildRect(frameworkElement);
                 DocumentNode    newValue         = this.CreateValue(frameworkElement);
                 if (newValue == null)
                 {
                     editTransaction.Cancel();
                 }
                 else if (this.CreateResource && this.ProcessAsResource(frameworkElement, newValue) == null)
                 {
                     editTransaction.Cancel();
                 }
                 else
                 {
                     if (this.ShouldReplaceOriginal)
                     {
                         this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)frameworkElement);
                         Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)frameworkElement, true);
                         this.SceneViewModel.ElementSelectionSet.Clear();
                         BaseFrameworkElement element = this.CreateElement(frameworkElement);
                         using (this.SceneViewModel.ForceBaseValue())
                         {
                             element.Name = frameworkElement.Name;
                             ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement);
                             int index = collectionForChild.IndexOf((SceneNode)frameworkElement);
                             frameworkElement.Remove();
                             this.Postprocess(frameworkElement, element, properties, childRect);
                             collectionForChild.Insert(index, (SceneNode)element);
                             SceneElementHelper.ApplyProperties((SceneNode)element, properties);
                             editTransaction.Update();
                             designerForChild.SetChildRect(element, childRect);
                         }
                         this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)element);
                     }
                     editTransaction.Commit();
                 }
             }
         }
     }
     finally
     {
         PerformanceUtility.EndPerformanceSequence(PerformanceEvent.Make3D);
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
 private bool CheckForCircularReference(IEnumerable <SceneElement> elementsToCopy, ITypeId newTypeId)
 {
     foreach (SceneElement rootElement in elementsToCopy)
     {
         foreach (SceneNode sceneNode in SceneElementHelper.GetLogicalTree(rootElement))
         {
             if (sceneNode.Type == newTypeId)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
        public override void Execute()
        {
            SceneElement rootElement = this.SceneViewModel.ActiveEditingContainer as SceneElement;

            using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.locked ? StringTable.UndoUnitLockAll : StringTable.UndoUnitUnlockAll))
            {
                foreach (SceneElement sceneElement in SceneElementHelper.GetElementTree(rootElement))
                {
                    if (sceneElement.CanLock)
                    {
                        sceneElement.IsLocked = this.locked;
                    }
                }
                editTransaction.Commit();
            }
        }
Ejemplo n.º 9
0
        public override void Execute()
        {
            SceneElement rootElement = this.SceneViewModel.ActiveEditingContainer as SceneElement;

            using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.show ? StringTable.UndoUnitShowAll : StringTable.UndoUnitHideAll))
            {
                foreach (SceneElement sceneElement in SceneElementHelper.GetElementTree(rootElement))
                {
                    if (sceneElement.CanHide)
                    {
                        sceneElement.IsHidden = !this.show;
                    }
                }
                editTransaction.Commit();
            }
        }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
0
 private void ClearPropertyOnTextRuns(PropertyReference propertyReference)
 {
     if (!RichTextBoxRangeElement.ShouldClearPropertyOnTextRuns((SceneNode)this, propertyReference))
     {
         return;
     }
     propertyReference = propertyReference.Subreference(0, 0);
     foreach (SceneNode sceneNode in SceneElementHelper.GetElementTree((SceneElement)this))
     {
         TextElementSceneElement elementSceneElement = sceneNode as TextElementSceneElement;
         if (elementSceneElement != null)
         {
             PropertyReference propertyReference1 = this.DesignerContext.PropertyManager.FilterProperty((SceneNode)elementSceneElement, propertyReference);
             if (propertyReference1 != null)
             {
                 elementSceneElement.ClearValue(propertyReference1);
             }
         }
     }
 }
Ejemplo n.º 12
0
        public override void RefreshAllInstances(DocumentReference documentReference, IDocument document)
        {
            SceneDocument sceneDocument = document as SceneDocument;

            if (sceneDocument == null)
            {
                return;
            }
            SceneViewModel sceneViewModel = this.GetSceneViewModel(sceneDocument);

            if (sceneViewModel == null)
            {
                return;
            }
            bool         flag        = false;
            SceneElement rootElement = sceneViewModel.RootNode as SceneElement;

            if (rootElement == null)
            {
                return;
            }
            using (SceneEditTransaction editTransaction = sceneDocument.CreateEditTransaction(StringTable.AssetFileUpdatedUndo, true))
            {
                foreach (SceneElement element in SceneElementHelper.GetLogicalTree(rootElement))
                {
                    if (this.DoesNodeReferenceUrl(element.DocumentNode, documentReference.Path))
                    {
                        this.RefreshInstance(element, sceneDocument, documentReference.Path);
                        flag = true;
                    }
                }
                if (flag)
                {
                    editTransaction.Commit();
                }
                else
                {
                    editTransaction.Cancel();
                }
            }
        }
Ejemplo n.º 13
0
 SceneNode ITriggerContainer.ResolveTargetName(string name)
 {
     return(!string.IsNullOrEmpty(name) ? SceneElementHelper.FindNode((SceneNode)this.VisualTreeRoot, name) : (SceneNode)this);
 }
        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();
                    }
                }
            }
        }
Ejemplo n.º 15
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");
        }
Ejemplo n.º 16
0
        private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group)
        {
            SceneElement parentElement = group.ParentElement;

            if (parentElement == null)
            {
                return(new SceneNode[0]);
            }
            transaction.Update();
            ILayoutDesigner designerForParent1       = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true);
            Rect            childRect                = designerForParent1.GetChildRect(group);
            Matrix          effectiveRenderTransform = group.GetEffectiveRenderTransform(false);

            SceneNode[] array = new SceneNode[group.DefaultContent.Count];
            group.DefaultContent.CopyTo(array, 0);
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                Transform[]         transformArray         = new Transform[array.Length];
                Point[]             pointArray             = new Point[array.Length];
                LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length];
                ILayoutDesigner     designerForParent2     = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true);
                for (int index = 0; index < array.Length; ++index)
                {
                    BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
                        pointArray[index]     = frameworkElement.RenderTransformOrigin;
                        designerForParent2.GetChildRect(frameworkElement);
                        LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement);
                        layoutCacheRecordArray[index] = layoutCacheRecord;
                    }
                }
                int num1;
                if (array.Length == 1 && array[0] is BaseFrameworkElement)
                {
                    int?fixedCapacity = group.DefaultContent.FixedCapacity;
                    num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false);
                }
                else
                {
                    num1 = 0;
                }
                bool flag = num1 != 0;
                if (flag)
                {
                    Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true);
                    SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties);
                    if (!SceneElementHelper.ApplyProperties(array[0], properties))
                    {
                        flag = false;
                    }
                }
                if (array.Length == 1 && array[0] is SceneElement)
                {
                    VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]);
                }
                using (this.SceneViewModel.ForceBaseValue())
                {
                    SceneElement sceneElement = (SceneElement)null;
                    for (int index = 0; index < array.Length; ++index)
                    {
                        BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement)
                            {
                                sceneElement = (SceneElement)frameworkElement;
                            }
                            DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode);
                            frameworkElement.Remove();
                        }
                    }
                    ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer();
                    int index1 = collectionContainer.IndexOf((SceneNode)group);
                    this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group);
                    this.SceneViewModel.RemoveElement((SceneNode)group);
                    Matrix matrix1 = effectiveRenderTransform;
                    matrix1.OffsetX = 0.0;
                    matrix1.OffsetY = 0.0;
                    for (int index2 = array.Length - 1; index2 >= 0; --index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value;
                            collectionContainer.Insert(index1, (SceneNode)frameworkElement);
                            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1));
                            if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity)
                            {
                                frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper));
                                if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset)
                                {
                                    frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5));
                                }
                            }
                        }
                    }
                    transaction.Update();
                    if (sceneElement != null)
                    {
                        this.SceneViewModel.SetLockedInsertionPoint(sceneElement);
                    }
                    bool[] flagArray = new bool[array.Length];
                    int    length    = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null && array[index2].Parent != null)
                        {
                            if (!flag)
                            {
                                LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2];
                                Rect  rect1  = layoutCacheRecord.Rect;
                                Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y);
                                Point point2 = effectiveRenderTransform.Transform(point1);
                                Rect  rect2  = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size);
                                designerForParent1.ClearUnusedLayoutProperties(frameworkElement);
                                designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None);
                            }
                            flagArray[index2] = true;
                            ++length;
                        }
                    }
                    SceneNode[] sceneNodeArray = new SceneNode[length];
                    int         num2           = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        if (flagArray[index2])
                        {
                            sceneNodeArray[num2++] = array[index2];
                        }
                    }
                    return(sceneNodeArray);
                }
            }
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 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();
     }
 }