/// <summary>
        /// Remove a layerage from a parents's children,
        /// and insert to parents's parents's children
        /// </summary>
        /// <param name="layerageCollection"> The layerage-collection. </param>
        /// <param name="layerage"> The layerage. </param>
        public static bool ReleaseGroupLayer(LayerageCollection layerageCollection, Layerage layerage)
        {
            Layerage parents = layerage.Parents;

            if (parents != null)
            {
                ILayer parentsLayer = parents.Self;

                IList <Layerage> parentsParentsChildren = layerageCollection.GetParentsChildren(parents);
                IList <Layerage> parentsChildren        = layerageCollection.GetParentsChildren(layerage);
                int parentsIndex = parentsChildren.IndexOf(parents);
                if (parentsIndex < 0)
                {
                    parentsIndex = 0;
                }
                if (parentsIndex > parentsParentsChildren.Count - 1)
                {
                    parentsIndex = parentsParentsChildren.Count - 1;
                }

                parentsChildren.Remove(layerage);
                parentsParentsChildren.Insert(parentsIndex, layerage);

                return(true);
            }
            return(false);
        }
Пример #2
0
        private static void _mezzanine(LayerageCollection layerageCollection, Layerage mezzanineLayer, IEnumerable <Layerage> mezzanineLayers)
        {
            //Layerages
            IEnumerable <Layerage> selectedLayerages = LayerageCollection.GetAllSelected(layerageCollection);
            Layerage outermost = LayerageCollection.FindOutermostLayerage(selectedLayerages);
            //if (outermost == null) return; // If count = 0, it will be useless.
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(outermost);
            int index = parentsChildren.IndexOf(outermost);

            if (index < 0)
            {
                index = 0;
            }

            if (mezzanineLayer != null)
            {
                mezzanineLayer.Self.IsSelected = true;
                parentsChildren.Insert(index, mezzanineLayer);//Insert
            }
            else if (mezzanineLayers != null)
            {
                foreach (Layerage child in mezzanineLayers)
                {
                    child.Self.IsSelected = true;
                    parentsChildren.Insert(index, child);//Insert
                }
            }
        }
        /// <summary>
        /// Group all selected layerages.
        /// </summary>
        /// <param name="customDevice"> The custom-device. </param>
        /// <param name="layerageCollection"> The layerage-collection. </param>
        public static void GroupAllSelectedLayers(CanvasDevice customDevice, LayerageCollection layerageCollection)
        {
            //Layerages
            IEnumerable <Layerage> selectedLayerages = LayerageCollection.GetAllSelected(layerageCollection);
            Layerage outermost = LayerageCollection.FindOutermostLayerage(selectedLayerages);

            if (outermost == null)
            {
                return;
            }
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(outermost);
            int index = parentsChildren.IndexOf(outermost);

            if (index < 0)
            {
                index = 0;
            }


            //GroupLayer
            GroupLayer groupLayer = new GroupLayer(customDevice)
            {
                IsSelected = true,
                IsExpand   = false,
                //Refactoring
                IsRefactoringTransformer = true,
            };
            Layerage groupLayerage = groupLayer.ToLayerage();

            LayerBase.Instances.Add(groupLayer);


            //Temp
            foreach (Layerage layerage in selectedLayerages)
            {
                ILayer layer = layerage.Self;

                IList <Layerage> childParentsChildren = layerageCollection.GetParentsChildren(layerage);
                childParentsChildren.Remove(layerage);
                layer.IsSelected = false;

                groupLayerage.Children.Add(layerage);
            }

            //Insert
            parentsChildren.Insert(index, groupLayerage);
        }
        /// <summary>
        /// Un group all group layerage
        /// </summary>
        public static void UnGroupAllSelectedLayer(LayerageCollection layerageCollection)
        {
            //Layerages
            IEnumerable <Layerage> selectedLayerages = LayerageCollection.GetAllSelected(layerageCollection);
            Layerage outermost = LayerageCollection.FindOutermostLayerage(selectedLayerages);

            if (outermost == null)
            {
                return;
            }
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(outermost);
            int index = parentsChildren.IndexOf(outermost);

            if (index < 0)
            {
                index = 0;
            }


            do
            {
                Layerage groupLayerage = selectedLayerages.FirstOrDefault(l => l.Self.Type == LayerType.Group);
                if (groupLayerage == null)
                {
                    break;
                }
                ILayer groupLayer = groupLayerage.Self;

                //Insert
                foreach (Layerage layerage in groupLayerage.Children)
                {
                    ILayer layer = layerage.Self;

                    layer.IsSelected = true;
                    parentsChildren.Insert(index, layerage);
                }
                groupLayerage.Children.Clear();

                //Remove
                {
                    IList <Layerage> groupLayerageParentsChildren = layerageCollection.GetParentsChildren(groupLayerage);
                    groupLayerageParentsChildren.Remove(groupLayerage);
                }
            } while (selectedLayerages.Any(l => l.Self.Type == LayerType.Group) == false);
        }
Пример #5
0
        /// <summary>
        /// Remove the mezzanine layerage.
        /// </summary>
        /// <param name="layerageCollection"> The layerage-collection. </param>
        /// <param name="mezzanineLayerage"> The mezzanine-layerage. </param>
        public static void RemoveMezzanine(LayerageCollection layerageCollection, Layerage mezzanineLayerage)
        {
            if (mezzanineLayerage == null)
            {
                return;
            }

            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(mezzanineLayerage);

            parentsChildren.Remove(mezzanineLayerage);
        }
        /// <summary>
        /// Move a layerage to the top of destination layerage.
        /// </summary>
        /// <param name="layerageCollection"> The layerage-collection. </param>
        /// <param name="destination"> The destination layerage. </param>
        /// <param name="source"> The source layerage. </param>
        /// <param name="isBottomInsert"> Insert to the top or bottom. </param>
        public static void Move(LayerageCollection layerageCollection, Layerage destination, Layerage source, bool isBottomInsert)
        {
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(destination);
            int index = parentsChildren.IndexOf(destination);

            if (isBottomInsert)
            {
                index++;
            }
            if (index < 0)
            {
                index = 0;
            }
            if (index > parentsChildren.Count - 1)
            {
                index = parentsChildren.Count - 1;
            }


            if (source.Parents != null)
            {
                //Refactoring
                //ILayer sourceParents = source.Parents.Self;
                //sourceParents.IsRefactoringTransformer = true;
                //sourceParents.IsRefactoringRender = true;
                //sourceParents.IsRefactoringIconRender = true;
                source.Parents.RefactoringParentsTransformer();
                source.Parents.RefactoringParentsRender();
                source.Parents.RefactoringParentsIconRender();
            }

            parentsChildren.Remove(source);
            parentsChildren.Insert(index, source);


            if (destination.Parents != null)
            {
                //Refactoring
                ILayer destinationParents = destination.Parents.Self;
                destinationParents.IsRefactoringTransformer = true;
                destinationParents.IsRefactoringRender      = true;
                destinationParents.IsRefactoringIconRender  = true;
                destination.Parents.RefactoringParentsTransformer();
                destination.Parents.RefactoringParentsRender();
                destination.Parents.RefactoringParentsIconRender();
            }
        }
        /// <summary>
        /// Remove a layerage.
        /// </summary>
        /// <param name="layerageCollection"> The layerage-collection. </param>
        /// <param name="removeLayerage"> The remove Layerage. </param>
        public static void Remove(LayerageCollection layerageCollection, Layerage removeLayerage)
        {
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(removeLayerage);

            parentsChildren.Remove(removeLayerage);
        }
        private static void _add(LayerageCollection layerageCollection, Layerage currentLayerage, Layerage layerage, IEnumerable <Layerage> layerages)
        {
            if (layerage != null)
            {
                if (layerage.Parents != null)
                {
                    //Refactoring
                    ILayer layerageParents = layerage.Parents.Self;
                    layerageParents.IsRefactoringTransformer = true;
                    layerageParents.IsRefactoringRender      = true;
                    layerageParents.IsRefactoringIconRender  = true;
                    layerage.Parents.RefactoringParentsTransformer();
                    layerage.Parents.RefactoringParentsRender();
                    layerage.Parents.RefactoringParentsIconRender();
                }

                IList <Layerage> layerageParentsChildren = layerageCollection.GetParentsChildren(layerage);
                layerageParentsChildren.Remove(layerage);
                currentLayerage.Children.Add(layerage);


                //Refactoring
                ILayer currentLayer = currentLayerage.Self;
                currentLayer.IsRefactoringTransformer = true;
                currentLayer.IsRefactoringRender      = true;
                currentLayer.IsRefactoringIconRender  = true;
                currentLayerage.RefactoringParentsTransformer();
                currentLayerage.RefactoringParentsRender();
                currentLayerage.RefactoringParentsIconRender();
            }
            else if (layerages != null)
            {
                foreach (Layerage child in layerages)
                {
                    if (child.Parents != null)
                    {
                        //Refactoring
                        ILayer childParents = child.Parents.Self;
                        childParents.IsRefactoringTransformer = true;
                        childParents.IsRefactoringRender      = true;
                        childParents.IsRefactoringIconRender  = true;
                        child.Parents.RefactoringParentsTransformer();
                        child.Parents.RefactoringParentsRender();
                        child.Parents.RefactoringParentsIconRender();
                    }


                    IList <Layerage> childParentsChildren = layerageCollection.GetParentsChildren(child);
                    childParentsChildren.Remove(child);
                    currentLayerage.Children.Add(child);


                    //Refactoring
                    ILayer currentLayer = currentLayerage.Self;
                    currentLayer.IsRefactoringTransformer = true;
                    currentLayer.IsRefactoringRender      = true;
                    currentLayer.IsRefactoringIconRender  = true;
                    currentLayerage.RefactoringParentsTransformer();
                    currentLayerage.RefactoringParentsRender();
                    currentLayerage.RefactoringParentsIconRender();
                }
            }
        }
        private static void _insert(LayerageCollection layerageCollection, Layerage destination, Layerage source, IEnumerable <Layerage> sources, bool isBottomInsert)
        {
            IList <Layerage> parentsChildren = layerageCollection.GetParentsChildren(destination);
            int index = parentsChildren.IndexOf(destination);

            if (isBottomInsert)
            {
                index++;
            }
            if (index < 0)
            {
                index = 0;
            }
            if (index > parentsChildren.Count - 1)
            {
                index = parentsChildren.Count - 1;
            }

            if (source != null)
            {
                if (source.Parents != null)
                {
                    //Refactoring
                    ILayer sourceParents = source.Parents.Self;
                    sourceParents.IsRefactoringTransformer = true;
                    sourceParents.IsRefactoringRender      = true;
                    sourceParents.IsRefactoringIconRender  = true;
                    source.Parents.RefactoringParentsTransformer();
                    source.Parents.RefactoringParentsRender();
                    source.Parents.RefactoringParentsIconRender();
                }


                IList <Layerage> sourceParentsChildren = layerageCollection.GetParentsChildren(source);
                sourceParentsChildren.Remove(source);
                parentsChildren.Insert(index, source);


                if (destination.Parents != null)
                {
                    //Refactoring
                    ILayer destinationParents = destination.Parents.Self;
                    destinationParents.IsRefactoringTransformer = true;
                    destinationParents.IsRefactoringRender      = true;
                    destinationParents.IsRefactoringIconRender  = true;
                    destination.Parents.RefactoringParentsTransformer();
                    destination.Parents.RefactoringParentsRender();
                    destination.Parents.RefactoringParentsIconRender();
                }
            }
            else if (sources != null)
            {
                foreach (Layerage child in sources)
                {
                    if (child.Parents != null)
                    {
                        //Refactoring
                        ILayer childParents = child.Parents.Self;
                        childParents.IsRefactoringTransformer = true;
                        childParents.IsRefactoringRender      = true;
                        childParents.IsRefactoringIconRender  = true;
                        child.Parents.RefactoringParentsTransformer();
                        child.Parents.RefactoringParentsRender();
                        child.Parents.RefactoringParentsIconRender();
                    }

                    IList <Layerage> childParentsChildren = layerageCollection.GetParentsChildren(child);
                    childParentsChildren.Remove(child);
                    parentsChildren.Insert(index, child);
                }
            }


            if (destination.Parents != null)
            {
                //Refactoring
                ILayer destinationParents = destination.Parents.Self;
                destinationParents.IsRefactoringTransformer = true;
                destinationParents.IsRefactoringRender      = true;
                destinationParents.IsRefactoringIconRender  = true;
                destination.Parents.RefactoringParentsTransformer();
                destination.Parents.RefactoringParentsRender();
                destination.Parents.RefactoringParentsIconRender();
            }
        }