Пример #1
0
        private bool ApplyDefaultInitializers(SceneNode node)
        {
            bool flag = false;

            if (this.ShouldUseDefaultInitializer)
            {
                foreach (DefaultInitializer defaultInitializer in DefaultTypeInstantiator.GetDefaultInitializers(node))
                {
                    flag = true;
                    defaultInitializer.InitializeDefaults((ModelItem)node.ModelItem, node.ModelItem.Context);
                }
            }
            return(flag);
        }
Пример #2
0
        public virtual SceneNode CreateInstance(ITypeId instanceType, ISceneInsertionPoint insertionPoint, Rect rect, OnCreateInstanceAction action)
        {
            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.PropertyInspectorFromCreate);
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.CreateElement);
            SceneView sceneView = this.sceneView;

            if (sceneView == null || !sceneView.IsEditable || insertionPoint == null)
            {
                return((SceneNode)null);
            }
            SceneNode rawInstance = this.CreateRawInstance(instanceType);

            if (rawInstance == null || !insertionPoint.CanInsert((ITypeId)rawInstance.Type))
            {
                return((SceneNode)null);
            }
            if (rect.IsEmpty)
            {
                rect = new Rect(0.0, 0.0, double.NaN, double.NaN);
            }
            if (double.IsInfinity(rect.Width))
            {
                rect.Width = double.NaN;
            }
            if (double.IsInfinity(rect.Height))
            {
                rect.Height = double.NaN;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitCreateControlFormat, new object[1]
                {
                    (object)instanceType.Name
                })))
                {
                    IExpandable expandable = insertionPoint.SceneElement as IExpandable;
                    if (expandable != null)
                    {
                        insertionPoint.SceneNode.SetValue(expandable.ExpansionProperty, (object)true);
                    }
                    bool flag = this.ShouldUseDefaultInitializer && Enumerable.Any <FeatureProvider>(DefaultTypeInstantiator.GetDefaultInitializers(rawInstance));
                    IList <SceneNode> nodes = (IList <SceneNode>)null;
                    if (!flag)
                    {
                        nodes = this.CreateNodeTreeOnInsertion(rawInstance);
                        this.ApplyBeforeInsertionDefaultsToElements(nodes, rawInstance, new DefaultTypeInstantiator.SceneElementNamingCallback(DefaultTypeInstantiator.TypeNameCallback));
                    }
                    SceneNode    layoutTarget    = DefaultTypeInstantiator.GetLayoutTarget(rawInstance);
                    SceneElement selectionTarget = DefaultTypeInstantiator.GetSelectionTarget(rawInstance);
                    this.ViewModel.ElementSelectionSet.Clear();
                    insertionPoint.Insert(rawInstance);
                    editTransaction.Update();
                    this.ApplyDefaultInitializers(rawInstance);
                    if (action != null)
                    {
                        action(rawInstance);
                        editTransaction.Update();
                    }
                    if (!flag)
                    {
                        this.ApplyAfterInsertionDefaultsToElements(nodes, rawInstance);
                    }
                    SceneElement sceneElement1 = layoutTarget as SceneElement;
                    EffectNode   effectNode    = layoutTarget as EffectNode;
                    if (sceneElement1 != null && sceneElement1.IsViewObjectValid)
                    {
                        if (selectionTarget != null)
                        {
                            this.ViewModel.ElementSelectionSet.SetSelection(selectionTarget);
                        }
                        this.SetLayout(insertionPoint, rect, rawInstance, layoutTarget, editTransaction);
                    }
                    else if (effectNode != null)
                    {
                        this.ViewModel.ChildPropertySelectionSet.SetSelection((SceneNode)effectNode);
                    }
                    else
                    {
                        for (SceneNode sceneNode = layoutTarget; sceneNode != null; sceneNode = sceneNode.Parent)
                        {
                            SceneElement sceneElement2 = sceneNode as SceneElement;
                            if (sceneElement2 != null && sceneElement2.Visual != null && sceneElement2.Visual is IViewVisual)
                            {
                                this.sceneView.EnsureVisible(sceneElement2.Visual);
                                break;
                            }
                        }
                    }
                    if (this.ViewModel.DesignerContext.AmbientPropertyManager != null)
                    {
                        this.ViewModel.DesignerContext.AmbientPropertyManager.ApplyAmbientProperties(rawInstance);
                    }
                    editTransaction.Commit();
                }
            }
            return(rawInstance);
        }