Esempio n. 1
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);
        }