Exemple #1
0
        public EditedZoneCommand executeCommand(EditedZoneCommand run)
        {
            foreach (var item in run.mRemove)
            {
                int count = mSeries.Count;
                for (int i = 0; i < count; i++)
                {
                    EditedZoneUnit item2 = mSeries[i];
                    if (item.mStart == item2.mStart && item.mEnd == item2.mEnd)
                    {
                        mSeries.RemoveAt(i);
                        break;
                    }
                }
            }

            foreach (var item in run.mAdd)
            {
                mSeries.Add((EditedZoneUnit)item.clone());
            }

            mSeries.Sort();

            return(new EditedZoneCommand(run.mRemove, run.mAdd));
        }
Exemple #2
0
        private EditedZoneCommand generateCommandAdd(EditedZoneUnit[] areas)
        {
            EditedZone work = (EditedZone)clone();

            for (int i = 0; i < areas.Length; i++)
            {
                EditedZoneUnit item = areas[i];
                if (item == null)
                {
                    continue;
                }
                work.mSeries.Add(new EditedZoneUnit(item.mStart, item.mEnd));
            }
            work.normalize();

            // thisに存在していて、workに存在しないものをremoveに登録
            List <EditedZoneUnit> remove = new List <EditedZoneUnit>();

            foreach (var itemThis in this.iterator())
            {
                bool found = false;
                foreach (var itemWork in work.iterator())
                {
                    if (itemThis.mStart == itemWork.mStart && itemThis.mEnd == itemWork.mEnd)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    remove.Add(new EditedZoneUnit(itemThis.mStart, itemThis.mEnd));
                }
            }

            // workに存在していて、thisに存在しないものをaddに登録
            List <EditedZoneUnit> add = new List <EditedZoneUnit>();

            foreach (var itemWork in work.iterator())
            {
                bool found = false;
                foreach (var itemThis in this.iterator())
                {
                    if (itemThis.mStart == itemWork.mStart && itemThis.mEnd == itemWork.mEnd)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    add.Add(new EditedZoneUnit(itemWork.mStart, itemWork.mEnd));
                }
            }

            work = null;
            return(new EditedZoneCommand(add, remove));
        }
Exemple #3
0
        public Object clone()
        {
            EditedZone ret   = new EditedZone();
            int        count = mSeries.Count;

            for (int i = 0; i < count; i++)
            {
                EditedZoneUnit p = mSeries[i];
                ret.mSeries.Add((EditedZoneUnit)p.clone());
            }
            return(ret);
        }
Exemple #4
0
        /// <summary>
        /// 重複している部分を統合する
        /// </summary>
        private void normalize()
        {
            bool changed = true;

            while (changed)
            {
                changed = false;
                int count = mSeries.Count;
                for (int i = 0; i < count - 1; i++)
                {
                    EditedZoneUnit itemi = mSeries[i];
                    if (itemi.mEnd < itemi.mStart)
                    {
                        int d = itemi.mStart;
                        itemi.mStart = itemi.mEnd;
                        itemi.mEnd   = d;
                    }
                    for (int j = i + 1; j < count; j++)
                    {
                        EditedZoneUnit itemj = mSeries[j];
                        if (itemj.mEnd < itemj.mStart)
                        {
                            int d = itemj.mStart;
                            itemj.mStart = itemj.mEnd;
                            itemj.mEnd   = d;
                        }
                        if (itemj.mStart == itemi.mStart && itemj.mEnd == itemi.mEnd)
                        {
                            mSeries.RemoveAt(j);
                            changed = true;
                            break;
                        }
                        else if (itemj.mStart <= itemi.mStart && itemi.mEnd <= itemj.mEnd)
                        {
                            mSeries.RemoveAt(i);
                            changed = true;
                            break;
                        }
                        else if (itemi.mStart <= itemj.mStart && itemj.mEnd <= itemi.mEnd)
                        {
                            mSeries.RemoveAt(j);
                            changed = true;
                            break;
                        }
                        else if (itemi.mStart <= itemj.mEnd && itemj.mEnd < itemi.mEnd)
                        {
                            itemj.mEnd = itemi.mEnd;
                            mSeries.RemoveAt(i);
                            changed = true;
                            break;
                        }
                        else if (itemi.mStart <= itemj.mStart && itemj.mStart <= itemi.mEnd)
                        {
                            itemi.mEnd = itemj.mEnd;
                            mSeries.RemoveAt(j);
                            changed = true;
                            break;
                        }
                    }
                    if (changed)
                    {
                        break;
                    }
                }
            }
            mSeries.Sort();
        }