public Poem GetNextPoem(Poem poem, bool forward)
        {
            {
                PoemCollection coll = null;

                if (poem.ParentBlockPart != null)
                {
                    coll = poem.ParentBlockPart.Poems;
                }
                else
                {
                    coll = poem.ParentBlock.Poems;
                }

                int indexLine = coll.IndexOf(poem);
                if (indexLine != -1)
                {
                    int nextIndex = indexLine + (forward ? 1 : -1);

                    if (0 <= nextIndex && nextIndex < coll.Count)
                    {
                        return(coll[nextIndex]);
                    }
                }
            }

            if (poem.ParentBlockPart != null)
            {
                SABlockPart nextBlockPart = GetNextBlockPart(poem.ParentBlockPart, forward);

                if (nextBlockPart != null)
                {
                    if (forward)
                    {
                        return(nextBlockPart.GetFirstPoem());
                    }
                    else
                    {
                        return(nextBlockPart.GetLastPoem());
                    }
                }
            }

            {
                SABlock nextBlock = GetNextBlock(poem.ParentBlock, forward);

                if (forward)
                {
                    return(nextBlock.GetFirstPoem());
                }
                else
                {
                    return(nextBlock.GetLastPoem());
                }
            }
        }
        internal PoemLineIdentifier GetID()
        {
            PoemLineIdentifier result = new PoemLineIdentifier();

            result.LineString = this.Line;

            PoemPart curPoemPart = this.ParentPoemPart;
            Poem     curPoem     = this.ParentPoem;

            result.PoemName      = curPoem.Name;
            result.PoemFirstLine = curPoem.GetFirstLine().Line;

            PoemLinesCollection collLines = null;

            if (curPoemPart != null)
            {
                collLines = curPoemPart.Lines;

                result.PoemPartName      = curPoemPart.Name;
                result.PoemPartFirstLine = curPoemPart.GetFirstLine().Line;
                result.PoemPartIndex     = curPoem.Parts.IndexOf(curPoemPart);
            }
            else
            {
                collLines = curPoem.Lines;
            }

            result.LineIndex = collLines.IndexOf(this);

            SABlockPart curBlockPart = curPoem.ParentBlockPart;
            SABlock     curBlock     = curPoem.ParentBlock;

            result.BlockName  = curBlock.Name;
            result.BlockIndex = curBlock.ParentSA.Blocks.IndexOf(curBlock);


            PoemCollection collPoems = null;

            if (curBlockPart != null)
            {
                collPoems = curBlockPart.Poems;

                result.BlockPartName      = curBlockPart.Name;
                result.BlockPartFirstLine = curBlockPart.GetFirstLine().Line;
                result.BlockPartIndex     = curBlock.Parts.IndexOf(curBlockPart);
            }
            else
            {
                collPoems = curBlock.Poems;
            }

            result.PoemIndex = collPoems.IndexOf(curPoem);

            return(result);
        }
Exemple #3
0
        internal PoemLine GetLineByID(PoemLineIdentifier lineId)
        {
            SABlock block = null;

            if (!string.IsNullOrEmpty(lineId.BlockName))
            {
                SABlock[] searchBlocks = this.GetBlockByName(lineId.BlockName);

                if (searchBlocks.Length == 1)
                {
                    block = searchBlocks[0];
                }
                else if (searchBlocks.Length > 1)
                {
                    foreach (SABlock item in searchBlocks)
                    {
                        if (this.Blocks.IndexOf(item) == lineId.BlockIndex)
                        {
                            block = item;
                            break;
                        }
                    }
                }
            }

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

            PoemCollection poemColl = null;

            if (!string.IsNullOrEmpty(lineId.BlockPartFirstLine) && lineId.BlockPartIndex.HasValue)
            {
                SABlockPart[] searchBlockParts = block.GetPartsByFirstLine(lineId.BlockPartFirstLine);

                if (searchBlockParts.Length == 1)
                {
                    poemColl = searchBlockParts[0].Poems;
                }
                else if (searchBlockParts.Length > 1)
                {
                    foreach (SABlockPart item in searchBlockParts)
                    {
                        if (block.Parts.IndexOf(item) == lineId.BlockPartIndex)
                        {
                            poemColl = item.Poems;
                            break;
                        }
                    }
                }
            }
            else
            {
                poemColl = block.Poems;
            }

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

            Poem poem = null;

            if (!string.IsNullOrEmpty(lineId.PoemFirstLine) && lineId.PoemIndex.HasValue)
            {
                Poem[] searchBlockParts = poemColl.GetPoemsByFirstLine(lineId.PoemFirstLine);

                if (searchBlockParts.Length == 1)
                {
                    poem = searchBlockParts[0];
                }
                else if (searchBlockParts.Length > 1)
                {
                    foreach (Poem item in searchBlockParts)
                    {
                        if (poemColl.IndexOf(item) == lineId.PoemIndex)
                        {
                            poem = item;
                            break;
                        }
                    }
                }
            }

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


            PoemLinesCollection linesColl = null;

            if (!string.IsNullOrEmpty(lineId.PoemPartFirstLine) && lineId.PoemPartIndex.HasValue)
            {
                PoemPart[] searchBlockParts = poem.GetPartsByFirstLine(lineId.PoemPartFirstLine);

                if (searchBlockParts.Length == 1)
                {
                    linesColl = searchBlockParts[0].Lines;
                }
                else if (searchBlockParts.Length > 1)
                {
                    foreach (PoemPart item in searchBlockParts)
                    {
                        if (poem.Parts.IndexOf(item) == lineId.PoemPartIndex)
                        {
                            linesColl = item.Lines;
                            break;
                        }
                    }
                }
            }
            else
            {
                linesColl = poem.Lines;
            }

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


            PoemLine line = null;

            if (!string.IsNullOrEmpty(lineId.LineString) && lineId.LineIndex.HasValue)
            {
                PoemLine[] searchBlockParts = linesColl.GetPoemsByFirstLine(lineId.LineString);

                if (searchBlockParts.Length == 1)
                {
                    line = searchBlockParts[0];
                }
                else if (searchBlockParts.Length > 1)
                {
                    foreach (PoemLine item in searchBlockParts)
                    {
                        if (linesColl.IndexOf(item) == lineId.LineIndex)
                        {
                            line = item;
                            break;
                        }
                    }
                }
            }

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

            return(line);
        }