public void MovePhraseTree(int Index, Point offset) { // move root Point p; List <int> moved = new List <int>(); p = phrases[Index].position; p.Offset(offset); phrases[Index].position = p; phrases[Index].GraphicClipRectangle = Rectangle.Empty; moved.Add(Index); Stack <StoredPhraseContext> procHelper = new Stack <StoredPhraseContext>(); procHelper.Push(new StoredPhraseContext() { A_i = 0, A_Index = Index, A_IndexOfParentClone = phrases.Count - 1 }); __procin: while (procHelper.Count > 0) { StoredPhraseContext sph = procHelper.Pop(); Index = sph.A_Index; int i = sph.A_i; //if childs is absent we returns to last context, otherwise we go deeper while (i < phrases[Index].PhraseConnectReferences.Count) { int ci = phrases[Index].PhraseConnectReferences[i]; if (!moved.Contains(ci)) //if (!ProcHContatains(Index, procHelper)) { p = phrases[ci].position; p.Offset(offset); phrases[ci].position = p; moved.Add(ci); phrases[ci].GraphicClipRectangle = Rectangle.Empty; //current procHelper.Push(new StoredPhraseContext() { A_i = i + 1, A_Index = Index, A_IndexOfParentClone = sph.A_IndexOfParentClone }); //next procHelper.Push(new StoredPhraseContext() { A_i = 0, A_Index = ci, A_IndexOfParentClone = phrases.Count - 1 }); } //next statement goto __procin; } } moved = null; }
public void ClonePhraseTree(int Index) { int baseline = phrases.Count - 1; List <int> processed = new List <int>(); Dictionary <int, int> cloned = new Dictionary <int, int>(); Phrase pc = phrases[Index].Clone() as Phrase; //Connect clone to origin parents foreach (Phrase prc in phrases) { if (prc.PhraseConnectReferences.Contains(Index)) { prc.PhraseConnectReferences.Add(phrases.Count); } } AddPhrase(pc); Stack <StoredPhraseContext> procHelper = new Stack <StoredPhraseContext>(); procHelper.Push(new StoredPhraseContext() { A_i = 0, A_Index = Index, A_IndexOfParentClone = phrases.Count - 1 }); __procin: while (procHelper.Count > 0) { StoredPhraseContext sph = procHelper.Pop(); Index = sph.A_Index; int i = sph.A_i; //if childs is absent we returns to last context, otherwise we go deeper //if (!processed.Contains(Index)) if (!ProcHContains(Index, procHelper)) { while (i < phrases[Index].PhraseConnectReferences.Count) { int ci = phrases[Index].PhraseConnectReferences[i]; //if (cloned.ContainsValue(ci)) if (ci >= baseline) { i++; continue; } if (!cloned.ContainsKey(ci)) { Phrase phraseClone = phrases[ci].Clone() as Phrase; phrases[sph.A_IndexOfParentClone].PhraseConnectReferences[i] = phrases.Count; phrases.Add(phraseClone); cloned.Add(ci, phrases.Count - 1); } else { phrases[sph.A_IndexOfParentClone].PhraseConnectReferences[i] = cloned[ci]; i++; continue; } //current procHelper.Push(new StoredPhraseContext() { A_i = i + 1, A_Index = Index, A_IndexOfParentClone = sph.A_IndexOfParentClone }); //next procHelper.Push(new StoredPhraseContext() { A_i = 0, A_Index = ci, A_IndexOfParentClone = phrases.Count - 1 }); //next statement goto __procin; } //processed.Add(Index); } } cloned = null; }