Ejemplo n.º 1
0
        // Copy constructor
        public StrDelta(StrDelta dlt)
        {
            this.from     = dlt.from;
            this.to       = dlt.to;
            this.fromList = dlt.fromList;
            this.toList   = dlt.toList;
            this.distance = dlt.distance;
            this.conflict = dlt.conflict;

            this.edits = new List <DItem>();
            foreach (DItem ed in dlt.edits)
            {
                this.edits.Add(new DItem(ed));
            }
        }
Ejemplo n.º 2
0
        private void buttonDiff_Click(object sender, RoutedEventArgs e)
        {
            foreach (EditItem qqei in editItems)
            {
                editItems[0].Copy_GUI_to_textGui();
                editItems[1].Copy_GUI_to_textGui();

                editItems[0].Copy_textRtb_to_textMain();
                editItems[1].Copy_textRtb_to_textMain();

                // for debug
                // string s0 = editItems[0].GetContent();
                // List<string> l0 = editItems[0].GetContent2();

                // Compare textMain-s
                // todo: generalize: compare pivot (0) to all others
                StrDelta dlt      = new StrDelta(editItems[0].textMain.strList, editItems[1].textMain.strList);
                int      distance = dlt.Compare();

                // for debug
                // string s1 = editItems[0].GetContent();
                // List<string> l1 = editItems[0].GetContent2();

                // Calculate 'paragraph' + update screen
                // todo: generalize: calculate for every editItems[]
                Paragraph paragraph = dlt.TextHighlight_strList(true, true);
                // fix this editItems[0].Copy_StrDelta_to_GUI(paragraph);

                paragraph = dlt.TextHighlight_strList(false, true);
                // fix this editItems[1].Copy_StrDelta_to_GUI(paragraph);

                // for debug
                // string s2 = editItems[0].GetContent();
                // List<string> l2 = editItems[0].GetContent2();
            }
        }
Ejemplo n.º 3
0
        // Join two StrDelta-objects i.e. merge the current StrDelta-object with a given StrDelta-object.
        // This function modifies this.edits and this.to.
        // The two StrDelta-objects must have the same this.from i.e. same ancestor.
        // The function returns 'false' if the merge is not feasible or in case of merge conflicts (i.e. two edits to be applied to the same item).
        // Error management: by error code.
        public bool Merge(StrDelta dlt)
        {
            StrDelta _dlt1 = new StrDelta(this);
            StrDelta _dlt2 = new StrDelta(dlt);

            this.edits    = new List <DItem>();
            this.conflict = false;

            if (this.from != dlt.from)
            {
                return(false);   // Input StrDelta must have the same 'from'
            }

            int i1 = 0;
            int i2 = 0;

            while (true)
            {
                int   winner = -1;  // -1=not_assigned; 0=edits_are_identical; 1=chosen_edit_1; 2=chosen_edit_2
                DItem from1  = null;
                DItem from2  = null;
                if (i1 < _dlt1.edits.Count)
                {
                    from1 = _dlt1.edits[i1];
                }
                if (i2 < _dlt2.edits.Count)
                {
                    from2 = _dlt2.edits[i2];
                }
                if ((from1 == null) && (from2 == null))     // If finished ...
                {
                    break;
                }
                if (from1 == null)                          // If 'from1' completely processed ...
                {
                    winner = 2;
                }
                if (from2 == null)                          // If 'from2' completely processed ...
                {
                    winner = 1;
                }

                if (winner == -1)
                {
                    // Justification: _dlt1 and _dlt1 can be compared because they are kept aligned (see code below)
                    // Justification: either 'width' or 'widthOtherSide' is zero
                    if (Util.RangeOverlapping(from1.pos, from1.pos + from1.width + from1.widthOtherSide - 1,
                                              from2.pos, from2.pos + from2.width + from2.widthOtherSide - 1)) // If the 2 edits overlap ...
                    {
                        if (!from1.IsEqual(from2))                                                            // ... and they differs ...
                        {
                            this.conflict = true;
                            return(false);
                        }
                    }
                    winner = _IntCompare(from1.pos, from2.pos);  // 0=edits_are_identical; 1=chosen_edit_1; 2=chosen_edit_2
                }

                if (winner == 0)            // If the 2 edits are identical ...
                {
                    this.edits.Add(new DItem(from1));

                    i1++;
                    i2++;
                }
                else if (winner == 1)       // If _dlt1 has been selected ...
                {
                    this.edits.Add(new DItem(from1));

                    // Align _dlt2: all 'loser's edits have to be shifted by the width of the 'winner'
                    int d = 0;                                       // 0 is used in case of 'mod'
                    if ((from1.add == true) && (from1.rem == false)) // If 'add' ...
                    {
                        d = from1.width + from1.widthOtherSide;
                    }
                    if ((from1.add == false) && (from1.rem == true))       // If 'rem' ...
                    {
                        d = -(from1.width + from1.widthOtherSide);
                    }
                    for (int j = i2; j < _dlt2.edits.Count; j++)
                    {
                        _dlt2.edits[j].pos_r += d;    // Align _dlt2
                    }
                    i1++;
                }
                else if (winner == 2)         // If _dlt2 has been selected ...
                {
                    this.edits.Add(new DItem(from2));

                    // Align _dlt1: all 'loser's edits have to be shifted by the width of the 'winner'
                    int d = 0;                                       // 0 is used in case of 'mod'
                    if ((from2.add == true) && (from2.rem == false)) // If 'add' ...
                    {
                        d = from2.width + from2.widthOtherSide;      // Justification: either 'width' or 'widthOtherSide' is zero
                    }
                    if ((from2.add == false) && (from2.rem == true)) // If 'rem' ...
                    {
                        d = -(from2.width + from2.widthOtherSide);
                    }
                    for (int j = i1; j < _dlt1.edits.Count; j++)
                    {
                        _dlt1.edits[j].pos_r += d;    // Align _dlt1
                    }
                    i2++;
                }
                else
                {
                    throw new Exception("Wrong 'winner'");
                }
            }

            ApplyEdits();   // Applies this.edits to this.from to calculate this.to

            return(true);
        }