示例#1
0
        /// <summary>
        /// Adds a new group layer at the specified path, creating all the groups along the way if necessary.
        /// The path should not contain the "Root" group, use a single "/" instead or nothing.
        /// For example, to create a group layer named "Group" under Root/MyGroup, call this with path="/MyGroup/Group".
        /// </summary>
        public LayerGroup CreateGroupLayerAt(string path, bool isSequence = false)
        {
            LayerGroup group = RootLayer;

            if (group == null)
            {
                return(null);
            }

            string[] nodes = path.Split(new string[] { "/", "\\" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < nodes.Length; i++)
            {
                Layer child = group.FindChild(nodes[i]);

                if (child == null || child.Type != LayerType.Group)
                {
                    child = new LayerGroup(nodes[i], isSequence);
                    group.Children.Add(child);
                }

                group = child as LayerGroup;
            }

            return(group);
        }
示例#2
0
        /// <summary>
        /// Finds a layer at the specified path. Does not create the groups along the way if not found.
        /// </summary>
        public Layer FindLayer(string path)
        {
            string[] nodes = path.Split(new string[] { "/", "\\" }, StringSplitOptions.RemoveEmptyEntries);

            LayerGroup parent = this;
            Layer      layer  = parent;

            for (int i = 0; i < nodes.Length; i++)
            {
                if (parent == null)
                {
                    return(null);
                }

                Layer child = parent.FindChild(nodes[i]);
                if (child == null)
                {
                    return(null);
                }

                if (i == nodes.Length - 1)
                {
                    return(child);
                }
                else
                {
                    parent = child as LayerGroup;
                }
            }

            return(layer);
        }