/// <summary> /// Gets the width of the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <param name="vwenv">The vwenv.</param> /// <returns></returns> protected int GetWidth(IPhContextOrVar ctxtOrVar, IVwEnv vwenv) { if (ctxtOrVar == null) { return(0); } switch (ctxtOrVar.ClassID) { case PhSequenceContext.kclsidPhSequenceContext: IPhSequenceContext seqCtxt = ctxtOrVar as IPhSequenceContext; int totalLen = 0; foreach (IPhPhonContext cur in seqCtxt.MembersRS) { totalLen += GetWidth(cur, vwenv); } return(totalLen); case PhIterationContext.kclsidPhIterationContext: return(GetIterCtxtWidth(ctxtOrVar as IPhIterationContext, vwenv) + (PILE_MARGIN * 2)); case PhVariable.kclsidPhVariable: return(GetStrWidth(m_x, null, vwenv) + (PILE_MARGIN * 2)); default: return(GetSimpleCtxtWidth(ctxtOrVar as IPhSimpleContext, vwenv) + (PILE_MARGIN * 2)); } }
/// <summary> /// Gets the width of the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <param name="vwenv">The vwenv.</param> /// <returns></returns> protected int GetWidth(IPhContextOrVar ctxtOrVar, IVwEnv vwenv) { if (ctxtOrVar == null) { return(0); } switch (ctxtOrVar.ClassID) { case PhSequenceContextTags.kClassId: var seqCtxt = (IPhSequenceContext)ctxtOrVar; int totalLen = 0; foreach (IPhPhonContext cur in seqCtxt.MembersRS) { totalLen += GetWidth(cur, vwenv); } return(totalLen); case PhIterationContextTags.kClassId: return(GetIterCtxtWidth(ctxtOrVar as IPhIterationContext, vwenv) + (PileMargin * 2)); case PhVariableTags.kClassId: return(GetStrWidth(m_x, null, vwenv) + (PileMargin * 2)); default: return(GetSimpleCtxtWidth(ctxtOrVar as IPhSimpleContext, vwenv) + (PileMargin * 2)); } }
int InsertContext(IPhContextOrVar ctxtOrVar, SelectionHelper sel, out int cellIndex) { m_removeCol = null; int cellId = GetCell(sel); switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: Rule.InputOS.Insert(0, ctxtOrVar); cellIndex = -1; return(ctxtOrVar.Hvo); case AffixRuleFormulaVc.ktagRightEmpty: Rule.InputOS.Add(ctxtOrVar); cellIndex = -1; return(ctxtOrVar.Hvo); default: var cellCtxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId); if (ctxtOrVar.ClassID == PhVariableTags.kClassId) { int index = cellCtxtOrVar.IndexInOwner; Rule.InputOS.Insert(index, ctxtOrVar); UpdateMappings(cellCtxtOrVar, ctxtOrVar); Rule.InputOS.Remove(cellCtxtOrVar); cellIndex = -1; return(ctxtOrVar.Hvo); } var seqCtxt = CreateSeqCtxt(cellCtxtOrVar as IPhPhonContext); cellIndex = InsertContextInto(ctxtOrVar as IPhSimpleContext, sel, seqCtxt); return(seqCtxt.Hvo); } }
protected override int RemoveItems(SelectionHelper sel, bool forward, out int cellIndex) { cellIndex = -1; int cellId = GetCell(sel); if (cellId == -1 || cellId == -2) { return(-1); } switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: case AffixRuleFormulaVc.ktagRightEmpty: return(-1); case MoAffixProcessTags.kflidOutput: return(RemoveFromOutput(forward, sel, out cellIndex) ? cellId : -1); default: var ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId); if (ctxtOrVar.ClassID == PhSequenceContextTags.kClassId) { var seqCtxt = (IPhSequenceContext)ctxtOrVar; if (seqCtxt.MembersRS.Count == 0 && forward) { // remove an empty column int prevCellId = GetPrevCell(seqCtxt.Hvo); cellIndex = GetCellCount(prevCellId) - 1; Rule.InputOS.Remove(seqCtxt); return(prevCellId); } bool reconstruct = RemoveContextsFrom(forward, sel, seqCtxt, false, out cellIndex); // if the column is empty, schedule it to be removed when the selection has changed if (seqCtxt.MembersRS.Count == 0) { m_removeCol = seqCtxt; } return(reconstruct ? seqCtxt.Hvo : -1); } int idx = GetIndexToRemove(new ICmObject[] { ctxtOrVar }, sel, forward); if (idx > -1 && !IsLastVariable(ctxtOrVar)) { var seqCtxt = m_cache.ServiceLocator.GetInstance <IPhSequenceContextFactory>().Create(); Rule.InputOS.Insert(ctxtOrVar.IndexInOwner, seqCtxt); // if the column is empty, schedule it to be removed when the selection has changed m_removeCol = seqCtxt; UpdateMappings(ctxtOrVar, seqCtxt); ctxtOrVar.PreRemovalSideEffects(); Rule.InputOS.Remove(ctxtOrVar); return(seqCtxt.Hvo); } return(-1); } }
internal static bool IsMorphBoundary(IPhContextOrVar ctxt) { if (ctxt == null) return false; if (ctxt.ClassID == PhSimpleContextBdryTags.kClassId) { var bdryCtxt = (IPhSimpleContextBdry) ctxt; if (bdryCtxt.FeatureStructureRA.Guid == LangProjectTags.kguidPhRuleMorphBdry) return true; } return false; }
internal static bool IsWordBoundary(IPhContextOrVar ctxt) { if (ctxt == null) { return(false); } if (ctxt.ClassID == PhSimpleContextBdryTags.kClassId) { var bdryCtxt = (IPhSimpleContextBdry)ctxt; if (bdryCtxt.FeatureStructureRA.Guid == LangProjectTags.kguidPhRuleWordBdry) { return(true); } } return(false); }
bool IsLastVariable(IPhContextOrVar ctxtOrVar) { if (ctxtOrVar.ClassID != PhVariableTags.kClassId) { return(false); } int numVars = 0; foreach (var cur in Rule.InputOS) { if (cur.ClassID == PhVariableTags.kClassId) { numVars++; } } return(numVars == 1); }
private void SelectionChanged(object sender, EventArgs e) { if (m_removeCol != null) { // if there is a column that is scheduled to be removed, go ahead and remove it now SelectionHelper sel = SelectionHelper.Create(m_view); int cellId = GetCell(sel); if (m_removeCol.Hvo != cellId) { UndoableUnitOfWorkHelper.Do(MEStrings.ksRuleUndoRemove, MEStrings.ksRuleRedoRemove, Rule, () => { m_removeCol.PreRemovalSideEffects(); Rule.InputOS.Remove(m_removeCol); m_removeCol = null; }); sel.RestoreSelectionAndScrollPos(); } } }
protected override int GetCellCount(int cellId) { switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: case AffixRuleFormulaVc.ktagRightEmpty: return(0); case MoAffixProcessTags.kflidOutput: return(Rule.OutputOS.Count); default: IPhContextOrVar ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId); if (ctxtOrVar.ClassID == PhSequenceContextTags.kClassId) { return(((IPhSequenceContext)ctxtOrVar).MembersRS.Count); } return(1); } }
/// <summary> /// Gets the number of lines needed to display the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <returns></returns> protected int GetNumLines(IPhContextOrVar ctxtOrVar) { if (ctxtOrVar == null) { return(1); } switch (ctxtOrVar.ClassID) { case PhSequenceContext.kclsidPhSequenceContext: IPhSequenceContext seqCtxt = ctxtOrVar as IPhSequenceContext; int maxNumLines = 1; foreach (IPhPhonContext cur in seqCtxt.MembersRS) { int numLines = GetNumLines(cur); if (numLines > maxNumLines) { maxNumLines = numLines; } } return(maxNumLines); case PhIterationContext.kclsidPhIterationContext: IPhIterationContext iterCtxt = ctxtOrVar as IPhIterationContext; return(GetNumLines(iterCtxt.MemberRA)); case PhSimpleContextNC.kclsidPhSimpleContextNC: int numFeats = 0; IPhSimpleContextNC ncCtxt = ctxtOrVar as IPhSimpleContextNC; if (ncCtxt.FeatureStructureRAHvo != 0 && ncCtxt.FeatureStructureRA.ClassID == PhNCFeatures.kclsidPhNCFeatures) { IPhNCFeatures natClass = ncCtxt.FeatureStructureRA as IPhNCFeatures; if (natClass.FeaturesOAHvo != 0) { numFeats = natClass.FeaturesOA.FeatureSpecsOC.Count; } } return(ncCtxt.PlusConstrRS.Count + ncCtxt.MinusConstrRS.Count + numFeats); } return(1); }
/// <summary> /// Gets the number of lines needed to display the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <returns></returns> protected int GetNumLines(IPhContextOrVar ctxtOrVar) { if (ctxtOrVar == null) { return(1); } switch (ctxtOrVar.ClassID) { case PhSequenceContextTags.kClassId: var seqCtxt = (IPhSequenceContext)ctxtOrVar; int maxNumLines = 1; foreach (IPhPhonContext cur in seqCtxt.MembersRS) { int numLines = GetNumLines(cur); if (numLines > maxNumLines) { maxNumLines = numLines; } } return(maxNumLines); case PhIterationContextTags.kClassId: var iterCtxt = (IPhIterationContext)ctxtOrVar; return(GetNumLines(iterCtxt.MemberRA)); case PhSimpleContextNCTags.kClassId: int numFeats = 0; var ncCtxt = (IPhSimpleContextNC)ctxtOrVar; if (ncCtxt.FeatureStructureRA != null && ncCtxt.FeatureStructureRA.ClassID == PhNCFeaturesTags.kClassId) { var natClass = (IPhNCFeatures)ncCtxt.FeatureStructureRA; if (natClass.FeaturesOA != null) { numFeats = natClass.FeaturesOA.FeatureSpecsOC.Count; } } return(ncCtxt.PlusConstrRS.Count + ncCtxt.MinusConstrRS.Count + numFeats); } return(1); }
protected override int GetItemCellIndex(int cellId, ICmObject obj) { switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: case AffixRuleFormulaVc.ktagRightEmpty: return(-1); case MoAffixProcessTags.kflidOutput: return(obj.IndexInOwner); default: IPhContextOrVar ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId); if (obj.ClassID == PhSequenceContextTags.kClassId) { var seqCtxt = (IPhSequenceContext)ctxtOrVar; return(seqCtxt.MembersRS.IndexOf(obj as IPhPhonContext)); } return(-1); } }
protected override int GetPrevCell(int cellId) { switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: return(-1); case AffixRuleFormulaVc.ktagRightEmpty: return(Rule.InputOS[Rule.InputOS.Count - 1].Hvo); case MoAffixProcessTags.kflidOutput: return(AffixRuleFormulaVc.ktagRightEmpty); default: IPhContextOrVar ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId); int index = ctxtOrVar.IndexInOwner; if (index == 0) { return(AffixRuleFormulaVc.ktagLeftEmpty); } return(Rule.InputOS[index - 1].Hvo); } }
/// <summary> /// Updates the context that the mappings point to. This is used when the context changes /// from a single context to a sequence context. /// </summary> /// <param name="oldCtxtOrVar"></param> /// <param name="newCtxtOrVar"></param> private void UpdateMappings(IPhContextOrVar oldCtxtOrVar, IPhContextOrVar newCtxtOrVar) { foreach (var mapping in Rule.OutputOS) { switch (mapping.ClassID) { case MoCopyFromInputTags.kClassId: var copy = (IMoCopyFromInput)mapping; if (copy.ContentRA == oldCtxtOrVar) { copy.ContentRA = newCtxtOrVar; } break; case MoModifyFromInputTags.kClassId: var modify = (IMoModifyFromInput)mapping; if (modify.ContentRA == oldCtxtOrVar) { modify.ContentRA = newCtxtOrVar; } break; } } }
/// <summary> /// Updates the context that the mappings point to. This is used when the context changes /// from a single context to a sequence context. /// </summary> /// <param name="oldCtxtOrVar"></param> /// <param name="newCtxtOrVar"></param> private void UpdateMappings(IPhContextOrVar oldCtxtOrVar, IPhContextOrVar newCtxtOrVar) { foreach (var mapping in Rule.OutputOS) { switch (mapping.ClassID) { case MoCopyFromInputTags.kClassId: var copy = (IMoCopyFromInput) mapping; if (copy.ContentRA == oldCtxtOrVar) copy.ContentRA = newCtxtOrVar; break; case MoModifyFromInputTags.kClassId: var modify = (IMoModifyFromInput) mapping; if (modify.ContentRA == oldCtxtOrVar) modify.ContentRA = newCtxtOrVar; break; } } }
bool IsLastVariable(IPhContextOrVar ctxtOrVar) { if (ctxtOrVar.ClassID != PhVariableTags.kClassId) return false; int numVars = 0; foreach (var cur in Rule.InputOS) { if (cur.ClassID == PhVariableTags.kClassId) numVars++; } return numVars == 1; }
protected override int RemoveItems(SelectionHelper sel, bool forward, out int cellIndex) { cellIndex = -1; int cellId = GetCell(sel); if (cellId == -1 || cellId == -2) return -1; switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: case AffixRuleFormulaVc.ktagRightEmpty: return -1; case MoAffixProcessTags.kflidOutput: return RemoveFromOutput(forward, sel, out cellIndex) ? cellId : -1; default: var ctxtOrVar = m_cache.ServiceLocator.GetInstance<IPhContextOrVarRepository>().GetObject(cellId); if (ctxtOrVar.ClassID == PhSequenceContextTags.kClassId) { var seqCtxt = (IPhSequenceContext) ctxtOrVar; if (seqCtxt.MembersRS.Count == 0 && forward) { // remove an empty column int prevCellId = GetPrevCell(seqCtxt.Hvo); cellIndex = GetCellCount(prevCellId) - 1; Rule.InputOS.Remove(seqCtxt); return prevCellId; } bool reconstruct = RemoveContextsFrom(forward, sel, seqCtxt, false, out cellIndex); // if the column is empty, schedule it to be removed when the selection has changed if (seqCtxt.MembersRS.Count == 0) m_removeCol = seqCtxt; return reconstruct ? seqCtxt.Hvo : -1; } int idx = GetIndexToRemove(new ICmObject[] { ctxtOrVar }, sel, forward); if (idx > -1 && !IsLastVariable(ctxtOrVar)) { var seqCtxt = m_cache.ServiceLocator.GetInstance<IPhSequenceContextFactory>().Create(); Rule.InputOS.Insert(ctxtOrVar.IndexInOwner, seqCtxt); // if the column is empty, schedule it to be removed when the selection has changed m_removeCol = seqCtxt; UpdateMappings(ctxtOrVar, seqCtxt); ctxtOrVar.PreRemovalSideEffects(); Rule.InputOS.Remove(ctxtOrVar); return seqCtxt.Hvo; } return -1; } }
int InsertContext(IPhContextOrVar ctxtOrVar, SelectionHelper sel, out int cellIndex) { m_removeCol = null; int cellId = GetCell(sel); switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: Rule.InputOS.Insert(0, ctxtOrVar); cellIndex = -1; return ctxtOrVar.Hvo; case AffixRuleFormulaVc.ktagRightEmpty: Rule.InputOS.Add(ctxtOrVar); cellIndex = -1; return ctxtOrVar.Hvo; default: var cellCtxtOrVar = m_cache.ServiceLocator.GetInstance<IPhContextOrVarRepository>().GetObject(cellId); if (ctxtOrVar.ClassID == PhVariableTags.kClassId) { int index = cellCtxtOrVar.IndexInOwner; Rule.InputOS.Insert(index, ctxtOrVar); UpdateMappings(cellCtxtOrVar, ctxtOrVar); Rule.InputOS.Remove(cellCtxtOrVar); cellIndex = -1; return ctxtOrVar.Hvo; } var seqCtxt = CreateSeqCtxt(cellCtxtOrVar as IPhPhonContext); cellIndex = InsertContextInto(ctxtOrVar as IPhSimpleContext, sel, seqCtxt); return seqCtxt.Hvo; } }
public override void UpdateSelection(IVwRootBox prootb, IVwSelection vwselNew) { if (m_removeCol != null) { // if there is a column that is scheduled to be removed, go ahead and remove it now SelectionHelper sel = SelectionHelper.Create(vwselNew, m_view); int cellId = GetCell(sel); if (m_removeCol.Hvo != cellId) { UndoableUnitOfWorkHelper.Do(MEStrings.ksRuleUndoRemove, MEStrings.ksRuleRedoRemove, Rule, () => { m_removeCol.PreRemovalSideEffects(); Rule.InputOS.Remove(m_removeCol); m_removeCol = null; }); sel.RestoreSelectionAndScrollPos(); return; } } base.UpdateSelection(prootb, vwselNew); }
public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); switch (frag) { case kfragContext: IPhContextOrVar ctxtOrVar = PhContextOrVar.CreateFromDBObject(m_cache, hvo); bool isOuterIterCtxt = false; // are we inside an iteration context? this is important since we only open a context pile if we are not // in an iteration context, since an iteration context does it for us if (vwenv.EmbeddingLevel > 0) { int outerHvo, outerTag, outerIndex; vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out outerHvo, out outerTag, out outerIndex); isOuterIterCtxt = m_cache.GetClassOfObject(outerHvo) == PhIterationContext.kclsidPhIterationContext; } switch (ctxtOrVar.ClassID) { case PhSequenceContext.kclsidPhSequenceContext: if (m_cache.GetVectorSize(hvo, (int)PhSequenceContext.PhSequenceContextTags.kflidMembers) > 0) { vwenv.AddObjVecItems((int)PhSequenceContext.PhSequenceContextTags.kflidMembers, this, kfragContext); } else { OpenContextPile(vwenv, false); vwenv.Props = m_bracketProps; vwenv.AddProp((int)PhSequenceContext.PhSequenceContextTags.kflidMembers, this, kfragEmpty); CloseContextPile(vwenv, false); } break; case PhSimpleContextNC.kclsidPhSimpleContextNC: IPhSimpleContextNC ncCtxt = ctxtOrVar as IPhSimpleContextNC; if (ncCtxt.FeatureStructureRAHvo != 0 && ncCtxt.FeatureStructureRA.ClassID == PhNCFeatures.kclsidPhNCFeatures) { // Natural class simple context with a feature-based natural class IPhNCFeatures natClass = ncCtxt.FeatureStructureRA as IPhNCFeatures; int numLines = GetNumLines(ncCtxt); if (numLines == 0) { if (!isOuterIterCtxt) { OpenContextPile(vwenv); } vwenv.AddProp(ktagInnerNonBoundary, this, kfragLeftBracket); vwenv.AddProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragQuestions); vwenv.AddProp(ktagInnerNonBoundary, this, kfragRightBracket); if (!isOuterIterCtxt) { CloseContextPile(vwenv); } } else if (numLines == 1) { if (!isOuterIterCtxt) { OpenContextPile(vwenv); } // use normal brackets for a single line context vwenv.AddProp(ktagInnerNonBoundary, this, kfragLeftBracket); // special consonant and vowel natural classes only display the abbreviation if (natClass.Abbreviation.AnalysisDefaultWritingSystem == "C" || natClass.Abbreviation.AnalysisDefaultWritingSystem == "V") { vwenv.AddObjProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragNC); } else { if (natClass.FeaturesOAHvo != 0 && natClass.FeaturesOA.FeatureSpecsOC.Count > 0) { vwenv.AddObjProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragFeatNC); } else if (ncCtxt.PlusConstrRS.Count > 0) { vwenv.AddObjVecItems((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidPlusConstr, this, kfragPlusVariable); } else { vwenv.AddObjVecItems((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidMinusConstr, this, kfragMinusVariable); } } vwenv.AddProp(ktagInnerNonBoundary, this, kfragRightBracket); if (!isOuterIterCtxt) { CloseContextPile(vwenv); } } else { // multiline context // left bracket pile int maxNumLines = MaxNumLines; vwenv.Props = m_bracketProps; vwenv.set_IntProperty((int)FwTextPropType.ktptMarginLeading, (int)FwTextPropVar.ktpvMilliPoint, PILE_MARGIN); vwenv.OpenInnerPile(); AddExtraLines(maxNumLines - numLines, ktagLeftNonBoundary, vwenv); vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftBracketUpHook); for (int i = 1; i < numLines - 1; i++) { vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftBracketExt); } vwenv.AddProp(ktagLeftBoundary, this, kfragLeftBracketLowHook); vwenv.CloseInnerPile(); // feature and variable pile vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalLeft); vwenv.OpenInnerPile(); AddExtraLines(maxNumLines - numLines, vwenv); vwenv.AddObjProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragFeatNC); vwenv.AddObjVecItems((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidPlusConstr, this, kfragPlusVariable); vwenv.AddObjVecItems((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidMinusConstr, this, kfragMinusVariable); vwenv.CloseInnerPile(); // right bracket pile vwenv.Props = m_bracketProps; if (!isOuterIterCtxt) { vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, PILE_MARGIN); } vwenv.OpenInnerPile(); AddExtraLines(maxNumLines - numLines, ktagRightNonBoundary, vwenv); vwenv.AddProp(ktagRightNonBoundary, this, kfragRightBracketUpHook); for (int i = 1; i < numLines - 1; i++) { vwenv.AddProp(ktagRightNonBoundary, this, kfragRightBracketExt); } vwenv.AddProp(ktagRightBoundary, this, kfragRightBracketLowHook); vwenv.CloseInnerPile(); } } else { // natural class context with segment-based natural class if (!isOuterIterCtxt) { OpenContextPile(vwenv); } vwenv.AddProp(ktagInnerNonBoundary, this, kfragLeftBracket); if (ncCtxt.FeatureStructureRAHvo != 0) { vwenv.AddObjProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragNC); } else { vwenv.AddProp((int)PhSimpleContextNC.PhSimpleContextNCTags.kflidFeatureStructure, this, kfragQuestions); } vwenv.AddProp(ktagInnerNonBoundary, this, kfragRightBracket); if (!isOuterIterCtxt) { CloseContextPile(vwenv); } } break; case PhIterationContext.kclsidPhIterationContext: IPhIterationContext iterCtxt = ctxtOrVar as IPhIterationContext; if (iterCtxt.MemberRAHvo != 0) { int numLines = GetNumLines(iterCtxt.MemberRA as IPhSimpleContext); if (numLines > 1) { vwenv.AddObjProp((int)PhIterationContext.PhIterationContextTags.kflidMember, this, kfragContext); DisplayIterCtxt(iterCtxt, numLines, vwenv); } else { OpenContextPile(vwenv); if (iterCtxt.MemberRA.ClassID == PhSimpleContextNC.kclsidPhSimpleContextNC) { vwenv.AddObjProp((int)PhIterationContext.PhIterationContextTags.kflidMember, this, kfragContext); } else { vwenv.AddProp(ktagInnerNonBoundary, this, kfragLeftParen); vwenv.AddObjProp((int)PhIterationContext.PhIterationContextTags.kflidMember, this, kfragContext); vwenv.AddProp(ktagInnerNonBoundary, this, kfragRightParen); } DisplayIterCtxt(iterCtxt, 1, vwenv); // Views doesn't handle selection properly when we have an inner pile with strings on either side, // so we don't add a zero-width space at the end CloseContextPile(vwenv, false); } } else { OpenContextPile(vwenv); vwenv.AddProp((int)PhIterationContext.PhIterationContextTags.kflidMember, this, kfragQuestions); CloseContextPile(vwenv); } break; case PhSimpleContextSeg.kclsidPhSimpleContextSeg: if (!isOuterIterCtxt) { OpenContextPile(vwenv); } if (m_cache.GetObjProperty(hvo, (int)PhSimpleContextSeg.PhSimpleContextSegTags.kflidFeatureStructure) != 0) { vwenv.AddObjProp((int)PhSimpleContextSeg.PhSimpleContextSegTags.kflidFeatureStructure, this, kfragTerminalUnit); } else { vwenv.AddProp((int)PhSimpleContextSeg.PhSimpleContextSegTags.kflidFeatureStructure, this, kfragQuestions); } if (!isOuterIterCtxt) { CloseContextPile(vwenv); } break; case PhSimpleContextBdry.kclsidPhSimpleContextBdry: if (!isOuterIterCtxt) { OpenContextPile(vwenv); } if (m_cache.GetObjProperty(hvo, (int)PhSimpleContextBdry.PhSimpleContextBdryTags.kflidFeatureStructure) != 0) { vwenv.AddObjProp((int)PhSimpleContextBdry.PhSimpleContextBdryTags.kflidFeatureStructure, this, kfragTerminalUnit); } else { vwenv.AddProp((int)PhSimpleContextBdry.PhSimpleContextBdryTags.kflidFeatureStructure, this, kfragQuestions); } if (!isOuterIterCtxt) { CloseContextPile(vwenv); } break; case PhVariable.kclsidPhVariable: OpenContextPile(vwenv); vwenv.AddProp(ktagXVariable, this, kfragXVariable); CloseContextPile(vwenv); break; } break; case kfragNC: int ncWs = m_cache.LangProject.ActualWs(LangProject.kwsFirstAnal, hvo, (int)PhNaturalClass.PhNaturalClassTags.kflidAbbreviation); if (ncWs != 0) { vwenv.AddStringAltMember((int)PhNaturalClass.PhNaturalClassTags.kflidAbbreviation, ncWs, this); } else { ncWs = m_cache.LangProject.ActualWs(LangProject.kwsFirstAnal, hvo, (int)PhNaturalClass.PhNaturalClassTags.kflidName); if (ncWs != 0) { vwenv.AddStringAltMember((int)PhNaturalClass.PhNaturalClassTags.kflidName, ncWs, this); } else { vwenv.AddProp((int)PhNaturalClass.PhNaturalClassTags.kflidAbbreviation, this, kfragQuestions); } } break; case kfragTerminalUnit: int tuWs = m_cache.LangProject.ActualWs(LangProject.kwsFirstVern, hvo, (int)PhTerminalUnit.PhTerminalUnitTags.kflidName); if (tuWs != 0) { vwenv.AddStringAltMember((int)PhTerminalUnit.PhTerminalUnitTags.kflidName, tuWs, this); } else { vwenv.AddProp((int)PhTerminalUnit.PhTerminalUnitTags.kflidName, this, kfragQuestions); } break; case kfragFeatNC: vwenv.AddObjProp((int)PhNCFeatures.PhNCFeaturesTags.kflidFeatures, this, kfragFeats); break; case kfragFeats: vwenv.AddObjVecItems((int)FsFeatStruc.FsFeatStrucTags.kflidFeatureSpecs, this, kfragFeature); break; case kfragFeature: vwenv.AddProp(ktagFeature, this, kfragFeatureLine); break; case kfragPlusVariable: vwenv.AddProp(ktagVariable, this, kfragPlusVariableLine); break; case kfragMinusVariable: vwenv.AddProp(ktagVariable, this, kfragMinusVariableLine); break; } }
/// <summary> /// Gets the number of lines needed to display the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <returns></returns> protected int GetNumLines(IPhContextOrVar ctxtOrVar) { if (ctxtOrVar == null) return 1; switch (ctxtOrVar.ClassID) { case PhSequenceContextTags.kClassId: IPhSequenceContext seqCtxt = ctxtOrVar as IPhSequenceContext; int maxNumLines = 1; foreach (IPhPhonContext cur in seqCtxt.MembersRS) { int numLines = GetNumLines(cur); if (numLines > maxNumLines) maxNumLines = numLines; } return maxNumLines; case PhIterationContextTags.kClassId: IPhIterationContext iterCtxt = ctxtOrVar as IPhIterationContext; return GetNumLines(iterCtxt.MemberRA); case PhSimpleContextNCTags.kClassId: int numFeats = 0; IPhSimpleContextNC ncCtxt = ctxtOrVar as IPhSimpleContextNC; if (ncCtxt.FeatureStructureRA != null && ncCtxt.FeatureStructureRA.ClassID == PhNCFeaturesTags.kClassId) { IPhNCFeatures natClass = ncCtxt.FeatureStructureRA as IPhNCFeatures; if (natClass.FeaturesOA != null) numFeats = natClass.FeaturesOA.FeatureSpecsOC.Count; } return ncCtxt.PlusConstrRS.Count + ncCtxt.MinusConstrRS.Count + numFeats; } return 1; }
/// <summary> /// Gets the width of the specified context or variable. /// </summary> /// <param name="ctxtOrVar">The context or variable.</param> /// <param name="vwenv">The vwenv.</param> /// <returns></returns> protected int GetWidth(IPhContextOrVar ctxtOrVar, IVwEnv vwenv) { if (ctxtOrVar == null) return 0; switch (ctxtOrVar.ClassID) { case PhSequenceContextTags.kClassId: var seqCtxt = ctxtOrVar as IPhSequenceContext; int totalLen = 0; foreach (IPhPhonContext cur in seqCtxt.MembersRS) totalLen += GetWidth(cur, vwenv); return totalLen; case PhIterationContextTags.kClassId: return GetIterCtxtWidth(ctxtOrVar as IPhIterationContext, vwenv) + (PILE_MARGIN * 2); case PhVariableTags.kClassId: return GetStrWidth(m_x, null, vwenv) + (PILE_MARGIN * 2); default: return GetSimpleCtxtWidth(ctxtOrVar as IPhSimpleContext, vwenv) + (PILE_MARGIN * 2); } }
int InsertContext(IPhContextOrVar ctxtOrVar, int fsFlid, int fsHvo, SelectionHelper sel, out int cellIndex) { m_removeColHvo = 0; int cellId = GetCell(sel); switch (cellId) { case AffixRuleFormulaVc.ktagLeftEmpty: Rule.InputOS.InsertAt(ctxtOrVar, 0); if (fsFlid != -1 && fsHvo != 0) m_cache.SetObjProperty(ctxtOrVar.Hvo, fsFlid, fsHvo); ctxtOrVar.NotifyNew(); cellIndex = -1; return ctxtOrVar.Hvo; case AffixRuleFormulaVc.ktagRightEmpty: Rule.InputOS.Append(ctxtOrVar); if (fsFlid != -1 && fsHvo != 0) m_cache.SetObjProperty(ctxtOrVar.Hvo, fsFlid, fsHvo); ctxtOrVar.NotifyNew(); cellIndex = -1; return ctxtOrVar.Hvo; default: if (ctxtOrVar.ClassID == PhVariable.kclsidPhVariable) { int index = m_cache.GetObjIndex(Rule.Hvo, (int)MoAffixProcess.MoAffixProcessTags.kflidInput, cellId); Rule.InputOS.InsertAt(ctxtOrVar, index); ctxtOrVar.NotifyNew(); UpdateMappings(cellId, ctxtOrVar.Hvo); Rule.InputOS.Remove(cellId); cellIndex = -1; return ctxtOrVar.Hvo; } else { IPhPhonContext cellCtxt = PhPhonContext.CreateFromDBObject(m_cache, cellId); IPhSequenceContext seqCtxt = CreateSeqCtxt(cellCtxt); cellIndex = InsertContextInto(ctxtOrVar as IPhSimpleContext, fsFlid, fsHvo, sel, seqCtxt); return seqCtxt.Hvo; } } }
private static XElement ExportContext(IPhContextOrVar context) { if (context == null) return null; XElement retVal; switch (context.ClassName) { default: throw new ArgumentException("Unrecognized context class."); case "PhVariable": retVal = new XElement("PhVariable", new XAttribute("Id", context.Hvo)); break; case "PhIterationContext": var asPhIterationContext = (IPhIterationContext) context; retVal = new XElement("PhIterationContext", new XAttribute("Id", context.Hvo), new XAttribute("Minimum", asPhIterationContext.Minimum), new XAttribute("Maximum", asPhIterationContext.Maximum), ExportItemAsReference(asPhIterationContext.MemberRA, "Member")); break; case "PhSequenceContext": var asPhSequenceContext = (IPhSequenceContext)context; retVal = new XElement("PhSequenceContext", new XAttribute("Id", context.Hvo), from member in asPhSequenceContext.MembersRS select ExportItemAsReference(member, asPhSequenceContext.MembersRS.IndexOf(member), "Members")); break; case "PhSimpleContextBdry": var asPhSimpleContextBdry = (IPhSimpleContextBdry)context; retVal = new XElement("PhSimpleContextBdry", new XAttribute("Id", asPhSimpleContextBdry.Hvo), CreateDstAttribute(asPhSimpleContextBdry.FeatureStructureRA)); break; case "PhSimpleContextSeg": var asPhSimpleContextSeg = (IPhSimpleContextSeg)context; retVal = new XElement("PhSimpleContextSeg", new XAttribute("Id", asPhSimpleContextSeg.Hvo), CreateDstAttribute(asPhSimpleContextSeg.FeatureStructureRA)); break; case "PhSimpleContextNC": var asPhSimpleContextNC = (IPhSimpleContextNC)context; retVal = new XElement("PhSimpleContextNC", new XAttribute("Id", asPhSimpleContextNC.Hvo), CreateDstAttribute(asPhSimpleContextNC.FeatureStructureRA), from plus in asPhSimpleContextNC.PlusConstrRS select ExportItemAsReference(plus, asPhSimpleContextNC.PlusConstrRS.IndexOf(plus), "PlusConstr"), from minus in asPhSimpleContextNC.MinusConstrRS select ExportItemAsReference(minus, asPhSimpleContextNC.MinusConstrRS.IndexOf(minus), "MinusConstr")); break; } return retVal; }
internal static bool IsMorphBoundary(IPhContextOrVar ctxt) { if (ctxt == null) return false; if (ctxt.ClassID == PhSimpleContextBdry.kclsidPhSimpleContextBdry) { IPhSimpleContextBdry bdryCtxt = ctxt as IPhSimpleContextBdry; if (bdryCtxt.FeatureStructureRA.Guid == LangProject.kguidPhRuleMorphBdry) return true; } return false; }