/// <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)); } }
void AppendToEnv(IPhPhonContext ctxt, int flid) { IPhSequenceContext seqCtxt = null; switch (flid) { case PhSegRuleRHSTags.kflidLeftContext: if (Rhs.LeftContextOA == null) { Rhs.LeftContextOA = ctxt; } else { seqCtxt = CreateSeqCtxt(flid); } break; case PhSegRuleRHSTags.kflidRightContext: if (Rhs.RightContextOA == null) { Rhs.RightContextOA = ctxt; } else { seqCtxt = CreateSeqCtxt(flid); } break; } if (seqCtxt != null) { m_cache.LangProject.PhonologicalDataOA.ContextsOS.Add(ctxt); seqCtxt.MembersRS.Add(ctxt); } }
IPhSequenceContext CreateSeqCtxt(int flid) { bool leftEnv = flid == (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidLeftContext; IPhPhonContext ctxt = leftEnv ? RHS.LeftContextOA : RHS.RightContextOA; if (ctxt == null) { return(null); } IPhSequenceContext seqCtxt = null; if (ctxt.ClassID != PhSequenceContext.kclsidPhSequenceContext) { m_cache.LangProject.PhonologicalDataOA.ContextsOS.Append(ctxt); seqCtxt = new PhSequenceContext(); if (leftEnv) { RHS.LeftContextOA = seqCtxt; } else { RHS.RightContextOA = seqCtxt; } seqCtxt.MembersRS.Append(ctxt); seqCtxt.NotifyNew(); } else { seqCtxt = ctxt as IPhSequenceContext; } return(seqCtxt); }
IPhSequenceContext CreateSeqCtxt(int flid) { bool leftEnv = flid == PhSegRuleRHSTags.kflidLeftContext; var ctxt = leftEnv ? RHS.LeftContextOA : RHS.RightContextOA; if (ctxt == null) { return(null); } IPhSequenceContext seqCtxt = null; if (ctxt.ClassID != PhSequenceContextTags.kClassId) { m_cache.LangProject.PhonologicalDataOA.ContextsOS.Add(ctxt); seqCtxt = m_cache.ServiceLocator.GetInstance <IPhSequenceContextFactory>().Create(); if (leftEnv) { RHS.LeftContextOA = seqCtxt; } else { RHS.RightContextOA = seqCtxt; } seqCtxt.MembersRS.Add(ctxt); } else { seqCtxt = ctxt as IPhSequenceContext; } return(seqCtxt); }
int GetIndex(IPhPhonContext ctxt, IPhPhonContext envCtxt, out IPhSequenceContext seqCtxt) { if (envCtxt.ClassID == PhSequenceContextTags.kClassId) { seqCtxt = (IPhSequenceContext)envCtxt; return(seqCtxt.MembersRS.IndexOf(ctxt)); } seqCtxt = null; return(-1); }
protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, IPhSequenceContext seqCtxt, bool preRemovalSideEffects, out int index) { index = -1; bool reconstruct = true; ICmObject[] ctxts = seqCtxt.MembersRS.Cast <ICmObject>().ToArray(); // if the selection is a range remove all items in the selection if (sel.IsRange) { int[] indices = GetIndicesToRemove(ctxts, sel); // return index of the item before the removed items if (indices.Length > 0) { index = indices[0] - 1; } foreach (int idx in indices) { // Sometimes when deleting a range, DeleteUnderlyingObject() takes out // parts of the rule before this loop gets to it. [LT-9775] if (ctxts[idx].IsValidObject) { ProcessIndicesSeqContext(ctxts, preRemovalSideEffects, idx); } } } else { int idx = GetIndexToRemove(ctxts, sel, forward); if (idx > -1) { // return index of the item before the removed items index = idx - 1; ProcessIndicesSeqContext(ctxts, preRemovalSideEffects, idx); } else { // if the backspace button is pressed at the beginning of a cell or the delete // button is pressed at the end of a cell, don't do anything reconstruct = false; } } return(reconstruct); }
int GetIndex(IPhPhonContext ctxt, IPhPhonContext envCtxt, out IPhSequenceContext seqCtxt) { if (envCtxt.ClassID == PhSequenceContext.kclsidPhSequenceContext) { seqCtxt = envCtxt as IPhSequenceContext; int[] hvos = seqCtxt.MembersRS.HvoArray; for (int i = 0; i < hvos.Length; i++) { if (ctxt.Hvo == hvos[i]) { return(i); } } } seqCtxt = null; return(-1); }
protected int InsertContextInto(IPhSimpleContext ctxt, SelectionHelper sel, IPhSequenceContext seqCtxt) { m_cache.LangProject.PhonologicalDataOA.ContextsOS.Add(ctxt); ICmObject[] ctxts = seqCtxt.MembersRS.Cast<ICmObject>().ToArray(); int index = GetInsertionIndex(ctxts, sel); seqCtxt.MembersRS.Insert(index, ctxt); // if the current selection is a range remove the items we are overwriting if (sel.IsRange) { var indices = GetIndicesToRemove(ctxts, sel); foreach (int idx in indices) { var c = (IPhPhonContext) ctxts[idx]; c.PreRemovalSideEffects(); m_cache.LangProject.PhonologicalDataOA.ContextsOS.Remove(c); } } return index; }
/// <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); }
bool DisplayOption(RuleInsertType type) { SelectionHelper sel = SelectionHelper.Create(m_view); int cellId = GetCell(sel); if (cellId < 0) { return(false); } switch (cellId) { case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidLeftContext: if (RHS.LeftContextOAHvo == 0) { return(true); } int[] leftHvos = null; IPhPhonContext first = null; if (RHS.LeftContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext) { leftHvos = new int[] { RHS.LeftContextOAHvo }; first = RHS.LeftContextOA; } else { IPhSequenceContext seqCtxt = RHS.LeftContextOA as IPhSequenceContext; if (seqCtxt.MembersRS.Count > 0) { first = seqCtxt.MembersRS[0]; } leftHvos = seqCtxt.MembersRS.HvoArray; } if (type == RuleInsertType.WORD_BOUNDARY) { // only display the word boundary option if we are at the beginning of the left context and // there is no word boundary already inserted if (sel.IsRange) { return(GetIndicesToRemove(leftHvos, sel)[0] == 0); } else { return(GetInsertionIndex(leftHvos, sel) == 0 && !IsWordBoundary(first)); } } else { // we cannot insert anything to the left of a word boundary in the left context return(sel.IsRange || GetInsertionIndex(leftHvos, sel) != 0 || !IsWordBoundary(first)); } case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidRightContext: if (RHS.RightContextOAHvo == 0 || sel.IsRange) { return(true); } int[] rightHvos = null; IPhPhonContext last = null; if (RHS.RightContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext) { rightHvos = new int[] { RHS.RightContextOAHvo }; last = RHS.RightContextOA; } else { IPhSequenceContext seqCtxt = RHS.RightContextOA as IPhSequenceContext; if (seqCtxt.MembersRS.Count > 0) { last = seqCtxt.MembersRS[seqCtxt.MembersRS.Count - 1]; } rightHvos = seqCtxt.MembersRS.HvoArray; } if (type == RuleInsertType.WORD_BOUNDARY) { // only display the word boundary option if we are at the end of the right context and // there is no word boundary already inserted if (sel.IsRange) { int[] indices = GetIndicesToRemove(rightHvos, sel); return(indices[indices.Length - 1] == rightHvos.Length - 1); } else { return(GetInsertionIndex(rightHvos, sel) == rightHvos.Length && !IsWordBoundary(last)); } } else { // we cannot insert anything to the right of a word boundary in the right context return(sel.IsRange || GetInsertionIndex(rightHvos, sel) != rightHvos.Length || !IsWordBoundary(last)); } default: return(type != RuleInsertType.WORD_BOUNDARY); } }
protected override int RemoveItems(SelectionHelper sel, bool forward, out int cellIndex) { cellIndex = -1; int cellId = GetCell(sel); switch (cellId) { case (int)PhRegularRule.PhSegmentRuleTags.kflidStrucDesc: IPhRegularRule rule = new PhRegularRule(m_cache, RHS.OwnerHVO); if (!RemoveContextsFrom(forward, sel, rule.StrucDescOS, true, out cellIndex)) { cellId = -1; } break; case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidStrucChange: if (RHS.StrucChangeOS == null) { cellId = -1; break; } if (!RemoveContextsFrom(forward, sel, RHS.StrucChangeOS, true, out cellIndex)) { cellId = -1; } break; case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidLeftContext: if (RHS.LeftContextOA == null) { cellId = -1; break; } if (RHS.LeftContextOA.ClassID == PhSequenceContext.kclsidPhSequenceContext) { IPhSequenceContext seqCtxt = RHS.LeftContextOA as IPhSequenceContext; if (!RemoveContextsFrom(forward, sel, seqCtxt, true, out cellIndex)) { cellId = -1; } } else { int idx = GetIndexToRemove(new int[] { RHS.LeftContextOAHvo }, sel, forward); if (idx > -1) { RHS.LeftContextOA.DeleteUnderlyingObject(); } else { cellId = -1; } } break; case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidRightContext: if (RHS.RightContextOA == null) { cellId = -1; break; } if (RHS.RightContextOA.ClassID == PhSequenceContext.kclsidPhSequenceContext) { IPhSequenceContext seqCtxt = RHS.RightContextOA as IPhSequenceContext; if (!RemoveContextsFrom(forward, sel, seqCtxt, true, out cellIndex)) { cellId = -1; } } else { int idx = GetIndexToRemove(new int[] { RHS.RightContextOAHvo }, sel, forward); if (idx > -1) { RHS.RightContextOA.DeleteUnderlyingObject(); } else { cellId = -1; } } break; } return(cellId); }
protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, IPhSequenceContext seqCtxt, bool deleteUnderlyingObject, out int index) { index = -1; bool reconstruct = true; int[] hvos = seqCtxt.MembersRS.HvoArray; // if the selection is a range remove all items in the selection if (sel.IsRange) { int[] indices = GetIndicesToRemove(hvos, sel); // return index of the item before the removed items if (indices.Length > 0) index = indices[0] - 1; foreach (int idx in indices) // Sometimes when deleting a range, DeleteUnderlyingObject() takes out // parts of the rule before this loop gets to it. [LT-9775] if (m_cache.IsValidObject(hvos[idx])) ProcessIndicesSeqContext(hvos, deleteUnderlyingObject, idx); } else { int idx = GetIndexToRemove(hvos, sel, forward); if (idx > -1) { // return index of the item before the removed items index = idx - 1; ProcessIndicesSeqContext(hvos, deleteUnderlyingObject, idx); } else { // if the backspace button is pressed at the beginning of a cell or the delete // button is pressed at the end of a cell, don't do anything reconstruct = false; } } return reconstruct; }
protected int InsertContextInto(IPhSimpleContext ctxt, int fsFlid, int fsHvo, SelectionHelper sel, IPhSequenceContext seqCtxt) { m_cache.LangProject.PhonologicalDataOA.ContextsOS.Append(ctxt); m_cache.SetObjProperty(ctxt.Hvo, fsFlid, fsHvo); ctxt.NotifyNew(); int[] hvos = seqCtxt.MembersRS.HvoArray; int index = GetInsertionIndex(hvos, sel); seqCtxt.MembersRS.InsertAt(ctxt, index); // if the current selection is a range remove the items we are overwriting if (sel.IsRange) { int[] indices = GetIndicesToRemove(hvos, sel); foreach (int idx in indices) { if (m_cache.LangProject.PhonologicalDataOA.ContextsOS.Contains(hvos[idx])) { IPhPhonContext removeCtxt = PhPhonContext.CreateFromDBObject(m_cache, hvos[idx]); removeCtxt.DeleteUnderlyingObject(); } } } return index; }
int GetIndex(IPhPhonContext ctxt, IPhPhonContext envCtxt, out IPhSequenceContext seqCtxt) { if (envCtxt.ClassID == PhSequenceContext.kclsidPhSequenceContext) { seqCtxt = envCtxt as IPhSequenceContext; int[] hvos = seqCtxt.MembersRS.HvoArray; for (int i = 0; i < hvos.Length; i++) { if (ctxt.Hvo == hvos[i]) return i; } } seqCtxt = null; return -1; }
int GetIndex(IPhPhonContext ctxt, IPhPhonContext envCtxt, out IPhSequenceContext seqCtxt) { if (envCtxt.ClassID == PhSequenceContextTags.kClassId) { seqCtxt = (IPhSequenceContext) envCtxt; return seqCtxt.MembersRS.IndexOf(ctxt); } seqCtxt = null; return -1; }