/// ------------------------------------------------------------------------------------ /// <summary> /// Get the versification table for this versification /// </summary> /// <param name="vers"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static VersificationTable Get(Paratext.ScrVers vers) { Debug.Assert(vers != Paratext.ScrVers.Unknown); if (versifications == null) versifications = new VersificationTable[versificationFiles.GetUpperBound(0)]; // Read versification table if not already read if (versifications[(int)vers] == null) { versifications[(int)vers] = new VersificationTable(vers); ReadVersificationFile(FileName(vers), versifications[(int)vers]); } return versifications[(int)vers]; }
// Get path of this versification file. // Fall back to eng.vrs if not present. private static string FileName(Paratext.ScrVers vers) { if (baseDir == null) throw new InvalidOperationException("VersificationTable.Initialize must be called first"); string fileName = Path.Combine(baseDir, GetFileNameForVersification(vers)); if (!File.Exists(fileName)) fileName = Path.Combine(baseDir, GetFileNameForVersification(Paratext.ScrVers.English)); return fileName; }
/// <summary> /// Gets the name of this requested versification file. /// </summary> /// <param name="vers">Versification scheme</param> public static string GetFileNameForVersification(Paratext.ScrVers vers) { return versificationFiles[(int)vers]; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy a reference, converting it to the specified versification if necessary /// </summary> /// ------------------------------------------------------------------------------------ public ScrReference(ScrReference from, Paratext.ScrVers targetVersification) : this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification) { VersificationTable.Get(targetVersification).ChangeVersification(this); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Parses the given string representing the reference range. /// </summary> /// <param name="sRefRng">The string representing the reference range.</param> /// <param name="bcvRefStart">The start reference (passed by ref because we use it to /// infer any components of the reference that are misisng in sRefRng).</param> /// <param name="bcvRefEnd">The end reference.</param> /// <param name="versification">The versification.</param> /// <returns> /// <c>true</c> if successfully parsed; <c>false</c> otherwise /// </returns> /// ------------------------------------------------------------------------------------ public static bool ParseRefRange(string sRefRng, ref BCVRef bcvRefStart, ref BCVRef bcvRefEnd, Paratext.ScrVers versification) { if (string.IsNullOrEmpty(sRefRng)) return false; if (!sRefRng.Contains("--")) return BCVRef.ParseRefRange(sRefRng, ref bcvRefStart, ref bcvRefEnd, false); sRefRng = sRefRng.Trim(); string[] pieces = sRefRng.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length != 2) return false; string sFirstRef = pieces[0]; int bbcccvvvStart = bcvRefStart.BBCCCVVV; bcvRefStart.Parse(sFirstRef); if (!bcvRefStart.Valid) { bcvRefStart.BBCCCVVV = bbcccvvvStart; return false; } string sEndRef = pieces[1]; int chapter; if (Int32.TryParse(sEndRef, out chapter)) { ScrReference scrRefEnd = new ScrReference(bcvRefStart.Book, chapter, 1, versification); scrRefEnd.Verse = scrRefEnd.LastVerse; bcvRefEnd.BBCCCVVV = scrRefEnd.BBCCCVVV; return true; } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Promote a simple BCV reference to a ScrReference /// </summary> /// <param name="from">The BCVRef to promote to a ScrReference.</param> /// <param name="versification">The versification.</param> /// ------------------------------------------------------------------------------------ public ScrReference(BCVRef from, Paratext.ScrVers versification) : this(from.Book, from.Chapter, from.Verse, from.Segment, versification) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a reference with a book, chapter, and verse /// </summary> /// <param name="book">The book.</param> /// <param name="chapter">The chapter.</param> /// <param name="verse">The verse.</param> /// <param name="versification">The versification scheme</param> /// ------------------------------------------------------------------------------------ public ScrReference(int book, int chapter, int verse, Paratext.ScrVers versification) : this(book, chapter, verse, 0, versification) { }
/// -------------------------------------------------------------------------------- /// <summary> /// Initializes a new object /// </summary> /// <param name="owner">The owner.</param> /// <param name="versification">The current versification to use when creating /// instances of ScrReference</param> /// -------------------------------------------------------------------------------- public DummyScrPassageDropDown(ScrPassageControl owner, Paratext.ScrVers versification) : base(owner, false, versification) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructs and returns a new ScrReference representing Revelation 22:21 (or whatver /// the last verse is in Revelation for the current default versification scheme). /// </summary> /// <param name="versification">The versification scheme.</param> /// ------------------------------------------------------------------------------------ public static ScrReference EndOfBible(Paratext.ScrVers versification) { VersificationTable versificationTable = VersificationTable.Get(versification); int lastChapter = versificationTable.LastChapter(LastBook); return new ScrReference(LastBook, lastChapter, versificationTable.LastVerse(LastBook, lastChapter), versification); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructs and returns a new ScrReference representing Genesis 1:1 /// </summary> /// <param name="versification">The versification scheme.</param> /// ------------------------------------------------------------------------------------ public static ScrReference StartOfBible(Paratext.ScrVers versification) { return new ScrReference(1, 1, 1, versification); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:ScrReference"/> class. /// </summary> /// <param name="strReference">The reference as a string.</param> /// <param name="versification">The versification scheme.</param> /// ------------------------------------------------------------------------------------ public ScrReference(string strReference, Paratext.ScrVers versification) : this(0, 0, 0, 0, versification) { Parse(strReference); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a reference, given all the pieces /// </summary> /// <param name="book">The book.</param> /// <param name="chapter">The chapter.</param> /// <param name="verse">The verse.</param> /// <param name="segment">The segment.</param> /// <param name="versification">The versification scheme.</param> /// ------------------------------------------------------------------------------------ public ScrReference(int book, int chapter, int verse, int segment, Paratext.ScrVers versification) : base(book, chapter, verse, segment) { m_versification = versification; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a reference with an initial BBCCCVVV value, a source versification, and a /// target versification /// </summary> /// <param name="initialRef">An integer representation of a scripture reference, where /// the first two digits are the canonical book number, the next three hold the chapter /// and the last three hold the verse number</param> /// <param name="srcVersification">The versification scheme assumed to be that of the /// initial BBCCCVVV value</param> /// <param name="targetVersification">The versification scheme to convert to. This will /// be the versification of the constructed ScrReference</param> /// ------------------------------------------------------------------------------------ public ScrReference(int initialRef, Paratext.ScrVers srcVersification, Paratext.ScrVers targetVersification) : this(new ScrReference(initialRef, srcVersification), targetVersification) { }
/// -------------------------------------------------------------------------------- /// <summary> /// Determines whether the ending reference of the previous section and the starting /// reference of the following section are contiguous. /// </summary> /// <param name="endRefOfSection">The ending reference of section.</param> /// <param name="startRefOfNextSection">The starting reference of following section.</param> /// <param name="bookId">The canonical number for the current book.</param> /// <param name="versification">The versification.</param> /// <returns> /// <c>true</c> if the sections do not have contiguous references, <c>false</c> /// otherwise /// </returns> /// -------------------------------------------------------------------------------- private static bool RefHasGap(BCVRef endRefOfSection, BCVRef startRefOfNextSection, int bookId, Paratext.ScrVers versification) { if (endRefOfSection.Chapter == startRefOfNextSection.Chapter) { // For references in the same chapter, determine whether the starting verse // in the next section is the same or just one more than the end of the // current section. return (endRefOfSection.Verse + 1) < startRefOfNextSection.Verse; } VersificationTable verseTable = VersificationTable.Get(versification); if ((endRefOfSection.Chapter + 1) == startRefOfNextSection.Chapter) { if (endRefOfSection.Verse != verseTable.LastVerse(bookId, endRefOfSection.Verse) || startRefOfNextSection.Verse == 1) { // The current section's last verse is the end of the chapter and the // next section starts with the first verse of the next chapter. return false; } } return true; }
// Create empty versification table private VersificationTable(Paratext.ScrVers vers) { this.scrVers = vers; bookList = new List<int[]>(); toStandard = new Dictionary<string, string>(); fromStandard = new Dictionary<string, string>(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a reference with an initial BBCCCVVV value /// </summary> /// <param name="initialRef"></param> /// <param name="versification">The versification scheme</param> /// ------------------------------------------------------------------------------------ public ScrReference(int initialRef, Paratext.ScrVers versification) : this(ScrReference.GetBookFromBcv(initialRef), ScrReference.GetChapterFromBcv(initialRef), ScrReference.GetVerseFromBcv(initialRef), versification) { }
/// ----------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ScrPassageDropDown"/> class. /// </summary> /// <param name="owner"></param> /// <param name="fBooksOnly">If true, show only books without chapter and verse</param> /// <param name="versification">The current versification to use when creating /// instances of ScrReference</param> /// ----------------------------------------------------------------------------------- public ScrPassageDropDown(Control owner, bool fBooksOnly, Paratext.ScrVers versification) { m_versification = versification; InitializeComponent(); InitializeButtons(); this.AttachedControl = owner; m_fBooksOnly = fBooksOnly; m_canceled = false; // Get reference from the main control m_scRef = ScrPassageControl.ScReference; LoadBooksButtons(); int initialBook = ScrPassageControl.ScReference.Book; // Verify that the book displayed in the text box portion of the scripture // passage control is valid. If it is, then find what button it corresponds to // and make that button current. if (ScrPassageControl.MulScrBooks.IsBookValid(initialBook) && Controls.Count > 0) { foreach (ScrDropDownButton button in m_buttons) { if (button.BCVValue == initialBook) { m_currButton = button.Index; button.State = ButtonState.Pushed; break; } } } }