예제 #1
0
		public AnnotationAdjuster(FdoCache cache, EditingHelper parent)
		{
			m_cache = cache;
			m_parentEditingHelper = parent;
			m_segDefn_note = cache.GetIdFromGuid(LangProject.kguidAnnNote);
			m_hvoSegDefn = cache.GetIdFromGuid(LangProject.kguidAnnTextSegment);
			if (m_segDefn_note == 0 || m_hvoSegDefn == 0)
			{
				m_segDefn_note = 0; // used to subsequently test for in-memory test disabling things.
				return; // In-memory testing, can't do anything useful.
			}
			m_cache.MainCacheAccessor.AddNotification(this);
			m_hvoAnnDefnTwfic = CmAnnotationDefn.Twfic(cache).Hvo;
			m_hvoSegDefn = CmAnnotationDefn.TextSegment(cache).Hvo;
			m_hvoPunctDefn = CmAnnotationDefn.Punctuation(cache).Hvo;
			m_hvoAnnErrorDefn = CmAnnotationDefn.Errors(cache).Hvo;

			m_segDefn_note = cache.GetIdFromGuid(LangProject.kguidAnnNote);
		}
예제 #2
0
		public BaseFreeformAdder(FdoCache cache)
		{
			m_fdoCache = cache;
			ktagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(cache);
			ktagSegFF_literalTranslation = cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
			ktagSegFF_freeTranslation = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			ktagSegFF_note = cache.GetIdFromGuid(LangProject.kguidAnnNote);
		}
예제 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets footnote hvo from reference in text properties
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="tprops"></param>
		/// <returns>Hvo of the footnote that was found or 0 if none was found</returns>
		/// ------------------------------------------------------------------------------------
		protected static int GetFootnoteFromProps(FdoCache cache, ITsTextProps tprops)
		{
			string footnoteRef =
				tprops.GetStrPropValue((int)FwTextPropType.ktptObjData);

			if (footnoteRef != null)
			{
				// first char. of strData is type code - GUID will follow it.
				Guid objGuid = MiscUtils.GetGuidFromObjData(footnoteRef.Substring(1));

				int hvo = cache.GetIdFromGuid(objGuid);
				if (hvo > 0 && cache.GetClassOfObject(hvo) == StFootnote.kClassId)
					return hvo;
			}
			return 0;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the list of categories based on categories in the specified filter.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private bool InitializeFromFilter(FdoCache cache, ICmFilter filter,
			out List<int> initiallySelectedList)
		{
			initiallySelectedList = new List<int>();

			if (filter == null || filter.RowsOS.Count == 0 || filter.RowsOS[0].CellsOS.Count == 0)
				return false;

			bool fFilterContainsCategories = false;

			// Get the pairs of class ids and flids.
			string[] pairs = filter.ColumnInfo.Split('|');
			Debug.Assert(filter.RowsOS[0].CellsOS.Count == pairs.Length);

			for (int i = 0; i < pairs.Length; i++)
			{
				ICmCell cell = filter.RowsOS[0].CellsOS[i];
				Guid guid;

				// Get the flid for this cell.
				string[] pair = pairs[i].Split(',');
				int flid = 0;
				int.TryParse(pair[1], out flid);

				if (flid == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidCategories)
				{
					fFilterContainsCategories = true;
					cell.ParseObjectMatchCriteria();
					if (cell.Contents.UnderlyingTsString.RunCount > 1)
					{
						guid = StringUtils.GetGuidFromRun(cell.Contents.UnderlyingTsString, 1);
						initiallySelectedList.Add(cache.GetIdFromGuid(guid));
					}
				}
			}

			return fFilterContainsCategories;
		}
예제 #5
0
		/// <summary>
		/// Init a CmPossibility (or derived class) based on a guid...typically one of our fixed guids used for
		/// objects we must identify absolutely.
		/// </summary>
		/// <param name="fcCache"></param>
		/// <param name="guid"></param>
		public void InitExisting(FdoCache fcCache, Guid guid)
		{
			int hvo = fcCache.GetIdFromGuid(guid);
			if (hvo == 0)
				throw new Exception("Failed to find object with guid " + guid);
			InitExisting(fcCache, hvo, false, false);
		}
예제 #6
0
		/// <summary>
		/// Load the information we need to display a paragraph of free (back) translations: for each paragraph
		/// load its segments, for each segment load the free translation. We assume the segments
		/// property of each paragraph already exists, and want the BeginOffset, EndOffset, BeginObject, and Free Translation
		/// properties of each segment, and the Comment of the FT.
		/// Also ensures all the segments are real and have an FT annotation.
		/// </summary>
		/// <param name="paragraphs"></param>
		/// <param name="cache"></param>
		/// <param name="ws"></param>
		public static void LoadSegmentFreeTranslations(int[] paragraphs, FdoCache cache, int ws)
		{
			int kflidSegments = SegmentsFlid(cache);
			List<int> segments = new List<int>();
			foreach (int hvoPara in paragraphs)
			{
				int[] segs = cache.GetVectorProperty(hvoPara, kflidSegments, true);
				int iseg = 0;
				foreach (int hvoSeg in segs)
				{
					int hvoRealSeg = hvoSeg;
					if (cache.IsDummyObject(hvoSeg))
						hvoRealSeg = CmBaseAnnotation.ConvertBaseAnnotationToReal(cache, hvoSeg).Hvo;
					segments.Add(hvoRealSeg);
					segs[iseg++] = hvoRealSeg;
				}
				// Update the list.
				cache.VwCacheDaAccessor.CacheVecProp(hvoPara, kflidSegments, segs, segs.Length);
			}

			if (segments.Count == 0)
				return; // somehow we can have none, and then the query fails.

			int hvoFt = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			string ids = JoinIds(segments.ToArray(), ",");
			int kflidFT = SegmentFreeTranslationFlid(cache);

			if (cache.DatabaseAccessor != null)
			{
				string sql =
					@"select seg.id, seg.BeginObject, seg.BeginOffset, seg.EndOffset, ft.id, ft.class$, ft.UpdStmp, ftc.Txt, ftc.Fmt from CmBaseAnnotation seg
					join CmIndirectAnnotation_AppliesTo ftseg on ftseg.Dst = seg.id
					join CmIndirectAnnotation_ ft on ft.id = ftseg.Src and ft.AnnotationType = " +
					hvoFt + @"
					left outer join CmAnnotation_Comment ftc on ftc.Obj = ft.id and ftc.ws = " + ws +
					@"
					where seg.id in (" + ids + ")";
				IDbColSpec dcs = DbColSpecClass.Create();
				dcs.Push((int) DbColType.koctBaseId, 0, 0, 0); // ID (of segment)
				dcs.Push((int) DbColType.koctObj, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject, 0);
				dcs.Push((int) DbColType.koctInt, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset, 0);
				dcs.Push((int) DbColType.koctInt, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset, 0);
				dcs.Push((int) DbColType.koctObj, 1, kflidFT, 0); // Free translation indirect annotation
				dcs.Push((int) DbColType.koctInt, 5, (int) CmObjectFields.kflidCmObject_Class, 0); // class of FT annotation
				dcs.Push((int) DbColType.koctTimeStamp, 5, 0, 0); // timestamp of FT annotation
				dcs.Push((int)DbColType.koctMlsAlt, 5, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
				dcs.Push((int)DbColType.koctFmt, 5, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
				cache.LoadData(sql, dcs, 0);
			}

			// Make sure each segment has a free translation.
			foreach (int hvoSeg in segments)
			{
				int hvoFT = cache.GetObjProperty(hvoSeg, kflidFT);
				if (hvoFT == 0)
				{
					ICmIndirectAnnotation ann = CmIndirectAnnotation.CreateUnownedIndirectAnnotation(cache);
					ann.AppliesToRS.Append(hvoSeg);
					ann.AnnotationTypeRAHvo = hvoFt;
					cache.VwCacheDaAccessor.CacheObjProp(hvoSeg, kflidFT, ann.Hvo);
				}
			}
		}
예제 #7
0
		private static void LoadSegmentFreeformAnnotationComments(FdoCache cache, string whereStatement, string orderByStatement, int[] wsIds)
		{
			int textSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnTextSegment);
			int ltSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
			int ftSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			int noteSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnNote);

			string sQryFf = String.Format("select ca.id,cc.Txt,34002,cc.ws,cc.Fmt from CmAnnotation ca"
				+ " join CmBaseAnnotation_ cts on cts.AnnotationType = " + textSegmentDefn
				+ " join CmIndirectAnnotation_AppliesTo caRef on caRef.Src = ca.id and caRef.Dst = cts.id "
				+ " join CmAnnotation_Comment cc on cc.obj = ca.id and cc.ws in (" + CmObject.JoinIds(wsIds, ",") + ")"
				+ " and ca.AnnotationType in (" + ltSegmentDefn + "," + ftSegmentDefn + "," + noteSegmentDefn + ") "
				+ " {0} {1}", whereStatement, orderByStatement);

			IVwOleDbDa dba = cache.MainCacheAccessor as IVwOleDbDa;
			IDbColSpec dcs = DbColSpecClass.Create();
			dcs.Push((int)DbColType.koctBaseId, 0, 0, 0); // First contains base IDs (of ff annotations).
			dcs.Push((int)DbColType.koctMlaAlt, 1, 0, 0); // Next contains the text of an ML prop of object in column 1.
			dcs.Push((int)DbColType.koctFlid, 1, 0, 0); // Next contains the flid of that ML prop (constant at 34002).
			dcs.Push((int)DbColType.koctEnc, 1, 0, 0); // Next contains the ws of that ML prop.
			dcs.Push((int)DbColType.koctFmt, 1, 0, 0); // Next contains the fmt info for the ML prop.

			dba.Load(sQryFf, dcs, 0, 0, null, false);
		}
예제 #8
0
		private static void LoadSegmentFreeformAnnotationData(FdoCache cache, string whereStatement, string orderByStatement, int[] segIds, int[] wsIds)
		{
			int ktagSegFF = SegmentFreeformAnnotationsFlid(cache);

			int textSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnTextSegment);
			int ltSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
			int ftSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			int noteSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnNote);
			// Retrieve CmAnnotations (which are really CmIndirectAnnotations, but there's no interesting
			// information in those tables) which
			// 1. ApplyTo the segment annotations above (cts), that is, the ones whose BeginObject is the StTxtPara
			// and whose type is Text Segment;
			// 2. Have one of the three types we're interested in.
			// The result columns are the ID of the text segment, the id of the ff annotation, the ID of the annotation type, and a txt, flid, ws, fmt set that
			// gives one of the alternatives of the Comment of the annotation.
			// We include cts.id in the order by so that, on the offchance that two segments begin at the same offset,
			// at least the annotations based on the same segment will be together.
			// We retrieve the contents of the annotations in a separate query as it is possible that the annotation
			// has been created but has no entry in CmAnnotation_Comment.
			string sQryFf = String.Format("select cts.id, ca.id, ca.AnnotationType from CmAnnotation ca"
				+ " join CmBaseAnnotation_ cts on cts.AnnotationType = " + textSegmentDefn
				+ " join CmIndirectAnnotation_AppliesTo caRef on caRef.Src = ca.id and caRef.Dst = cts.id "
				+ " and ca.AnnotationType in (" + ltSegmentDefn + "," + ftSegmentDefn + "," + noteSegmentDefn + ")"
				+ " {0} {1}", whereStatement, orderByStatement);
			IVwOleDbDa dba = cache.MainCacheAccessor as IVwOleDbDa;
			IDbColSpec dcs = DbColSpecClass.Create();
			dcs.Push((int)DbColType.koctBaseId, 0, 0, 0); // First column contains IDs that are the base of properties (the segments).
			dcs.Push((int)DbColType.koctObjVec, 1, ktagSegFF, 0); // Second contains sequences of ff annotations of those objects.
			dcs.Push((int)DbColType.koctObj, 2, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType, 0); // Third contains type of ff annotation.

			dba.Load(sQryFf, dcs, 0, 0, null, false);

			LoadSegmentFreeformAnnotationComments(cache, whereStatement, orderByStatement, wsIds);
			RemoveDuplicateSegmentFreeformAnnotations(cache, segIds, wsIds);
		}
예제 #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructs a new instance of the <see cref="ExportXml"/> class.
		/// </summary>
		/// <param name="fileName">pathname of the XML file to create</param>
		/// <param name="cache">data source</param>
		/// <param name="filter">lists the books to export</param>
		/// <param name="what">tells what to export: everything, filtered list, or single book</param>
		/// <param name="nBook">if single book, number of the book to export</param>
		/// <param name="iFirstSection">if single book, index of first section to export</param>
		/// <param name="iLastSection">if single book, index of last section to export</param>
		/// <param name="sDescription"></param>
		/// ------------------------------------------------------------------------------------
		public ExportXml(string fileName, FdoCache cache, FilteredScrBooks filter,
			ExportWhat what, int nBook, int iFirstSection, int iLastSection, string sDescription)
		{
			m_fileName = fileName;
			m_cache = cache;
			m_wsEnglish = m_cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en");
			m_bookFilter = filter;
			m_what = what;
			m_nBookSingle = nBook;
			m_iFirstSection = iFirstSection;
			m_iLastSection = iLastSection;
			m_sDescription = sDescription;
			m_scr = cache.LangProject.TranslatedScriptureOA;
			m_hvoFtSegmentDefn = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
		}
예제 #10
0
		internal static int GetAnnDefnId(FdoCache cache, Guid guid, ref int cachedVal)
		{
			if (cachedVal == 0)
			{
				cachedVal = cache.GetIdFromGuid(guid);
			}
			return cachedVal;

		}