コード例 #1
0
        private static Dictionary <IPropertyId, List <SceneNode> > StoreChildren(SceneElement sourceElement)
        {
            Dictionary <IPropertyId, List <SceneNode> > dictionary = new Dictionary <IPropertyId, List <SceneNode> >();

            foreach (IPropertyId propertyId in sourceElement.ContentProperties)
            {
                ISceneNodeCollection <SceneNode> collectionForProperty = sourceElement.GetCollectionForProperty(propertyId);
                if (collectionForProperty != null)
                {
                    while (collectionForProperty.Count > 0)
                    {
                        SceneNode sceneNode = collectionForProperty[0];
                        if (sceneNode.DocumentNode != null)
                        {
                            DocumentNodeHelper.PreserveFormatting(sceneNode.DocumentNode);
                        }
                        sceneNode.Remove();
                        List <SceneNode> list = (List <SceneNode>)null;
                        if (!dictionary.TryGetValue(propertyId, out list))
                        {
                            list = new List <SceneNode>();
                            dictionary.Add(propertyId, list);
                        }
                        list.Add(sceneNode);
                    }
                }
            }
            return(dictionary);
        }
コード例 #2
0
        public static Dictionary <IPropertyId, SceneNode> StoreProperties(SceneNode sourceNode, IEnumerable <IPropertyId> propertyFilter, bool detachProperties)
        {
            Dictionary <IPropertyId, SceneNode> dictionary = new Dictionary <IPropertyId, SceneNode>();
            List <IPropertyId> list = new List <IPropertyId>();
            ReadOnlyCollection <IPropertyId> contentProperties     = sourceNode.ContentProperties;
            DocumentCompositeNode            documentCompositeNode = sourceNode.DocumentNode as DocumentCompositeNode;

            if (documentCompositeNode != null)
            {
                if (propertyFilter == null)
                {
                    foreach (IPropertyId propertyId in (IEnumerable <IProperty>)documentCompositeNode.Properties.Keys)
                    {
                        list.Add(propertyId);
                    }
                }
                else
                {
                    foreach (IPropertyId propertyId in propertyFilter)
                    {
                        IProperty property = sourceNode.ProjectContext.ResolveProperty(propertyId);
                        if (property != null && documentCompositeNode.Properties.Keys.Contains(property))
                        {
                            list.Add((IPropertyId)property);
                        }
                    }
                }
            }
            foreach (IPropertyId propertyId in list)
            {
                if (!contentProperties.Contains(propertyId))
                {
                    DocumentNode node;
                    using (sourceNode.ViewModel.ForceBaseValue())
                        node = sourceNode.GetLocalValueAsDocumentNode(propertyId).Node;
                    if (node != null)
                    {
                        if (detachProperties)
                        {
                            DocumentNodeHelper.PreserveFormatting(node);
                            sourceNode.ClearLocalValue(propertyId);
                        }
                        else
                        {
                            node = node.Clone(sourceNode.DocumentContext);
                        }
                        dictionary.Add(propertyId, sourceNode.ViewModel.GetSceneNode(node));
                    }
                }
            }
            return(dictionary);
        }
コード例 #3
0
ファイル: BehaviorHelper.cs プロジェクト: radtek/Shopdrawing
        internal static void ReparentAction(ISceneNodeCollection <SceneNode> triggersCollection, BehaviorTriggerBaseNode oldTrigger, BehaviorTriggerBaseNode newTrigger, BehaviorTriggerActionNode action)
        {
            SceneViewModel viewModel = oldTrigger.ViewModel;

            viewModel.BehaviorSelectionSet.Clear();
            int num = triggersCollection.IndexOf((SceneNode)oldTrigger);

            DocumentNodeHelper.PreserveFormatting(action.DocumentNode);
            oldTrigger.Actions.Remove((SceneNode)action);
            viewModel.Document.OnUpdatedEditTransaction();
            if (oldTrigger.Actions.Count == 0)
            {
                triggersCollection.RemoveAt(num--);
            }
            if (!triggersCollection.Contains((SceneNode)newTrigger))
            {
                triggersCollection.Insert(num + 1, (SceneNode)newTrigger);
            }
            newTrigger.Actions.Add((SceneNode)action);
            viewModel.BehaviorSelectionSet.SetSelection((BehaviorBaseNode)action);
        }
コード例 #4
0
 public static void PrepareNodeForTextDeletion(IDocumentRoot documentRoot, DocumentNode node)
 {
     node.ClearOldSourceContainerContext();
     DocumentNodeHelper.PreserveFormatting(documentRoot, node);
 }
コード例 #5
0
ファイル: UngroupCommand.cs プロジェクト: radtek/Shopdrawing
        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);
                }
            }
        }
コード例 #6
0
ファイル: BehaviorHelper.cs プロジェクト: radtek/Shopdrawing
        public static void DeleteBehavior(BehaviorBaseNode node)
        {
            Stack <ReferenceStep> input   = new Stack <ReferenceStep>();
            SceneNode             parent1 = node.Parent;
            SceneNode             child1  = (SceneNode)node;

            while (true)
            {
                ReferenceStep referenceStep = (ReferenceStep)parent1.GetPropertyForChild(child1);
                if (parent1.IsCollectionProperty((IPropertyId)referenceStep))
                {
                    int index = parent1.GetCollectionForProperty((IPropertyId)referenceStep).IndexOf(child1);
                    input.Push((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)node.ProjectContext, (ITypeId)referenceStep.PropertyType, index));
                }
                input.Push(referenceStep);
                if (!(parent1 is SceneElement))
                {
                    child1  = parent1;
                    parent1 = parent1.Parent;
                }
                else
                {
                    break;
                }
            }
            SceneElement      sceneElement      = (SceneElement)parent1;
            SceneNode         parent2           = node.Parent;
            PropertyReference propertyReference = new PropertyReference(input);

            node.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sceneElement, propertyReference.ToString());
            SceneNode child2 = (SceneNode)node;
            int       num    = propertyReference.Count - 1;
            ISceneNodeCollection <SceneNode> collectionForChild;
            int endIndex;

            while (true)
            {
                SceneNode parent3 = child2.Parent;
                if (sceneElement != child2 && parent3 != null)
                {
                    ReferenceStep referenceStep = (ReferenceStep)parent3.GetPropertyForChild(child2);
                    collectionForChild = parent3.GetCollectionForChild(child2);
                    DocumentNodeHelper.PreserveFormatting(child2.DocumentNode);
                    endIndex = propertyReference.ReferenceSteps.IndexOf(referenceStep);
                    if (collectionForChild.Count == 1)
                    {
                        child2.Remove();
                        child2 = parent3;
                    }
                    else
                    {
                        goto label_10;
                    }
                }
                else
                {
                    break;
                }
            }
            sceneElement.ClearValue((IPropertyId)propertyReference.FirstStep);
            goto label_11;
label_10:
            int index1 = collectionForChild.IndexOf(child2);

            child2.ViewModel.AnimationEditor.ValidateAnimations((SceneNode)sceneElement, propertyReference.Subreference(0, endIndex), index1, false);
            child2.Remove();
label_11:
            node.ViewModel.Document.OnUpdatedEditTransaction();
        }