프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Events / UndoCommand.cs @ 299f2c11

이력 | 보기 | 이력해설 | 다운로드 (5.99 KB)

1 d128ceb2 humkyung
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Controls.Line;
4
using MarkupToPDF.Controls.Polygon;
5
using MarkupToPDF.Controls.Shape;
6
using MarkupToPDF.Controls.Text;
7
using MarkupToPDF.Controls.Etc;
8
using System;
9
using System.Collections.Generic;
10
using System.Linq;
11
using System.Text;
12
using System.Windows;
13
using System.Windows.Controls;
14
using System.Windows.Media;
15
using MarkupToPDF.Controls.Cad;
16
using KCOM.Common;
17 f816dd63 humkyung
using KCOM.Controls;
18 4eb052e4 ljiyeon
using MarkupToPDF.Controls.Parsing;
19 d128ceb2 humkyung
20
namespace KCOM.Events
21
{
22
    public class UndoCommand
23
    {
24
        private static readonly UndoCommand _instance = new UndoCommand();
25
26
        // Explicit static constructor to tell C# compiler
27
        // not to mark type as beforefieldinit
28
        static UndoCommand()
29
        {
30
        }
31
32
        private UndoCommand()
33
        {
34
        }
35
36
        public static UndoCommand Instance
37
        {
38
            get
39
            {
40
                return _instance;
41
            }
42
        }
43
44
        /// <summary>
45
        /// push undo data
46
        /// </summary>
47
        /// <author>humkyung</author>
48 f258d884 humkyung
        /// <date>2019.06.14, 2024.04.26</date>
49 d128ceb2 humkyung
        /// <param name="comments"></param>
50 34ac8db7 humkyung
        public void Push(EventType _EventType, ICollection<CommentUserInfo> comments)
51 d128ceb2 humkyung
        {
52 873011c4 humkyung
            UndoDataGroup UndoData = new UndoDataGroup()
53 d128ceb2 humkyung
            {
54
                IsUndo = false,
55 34ac8db7 humkyung
                Event = _EventType,
56 d128ceb2 humkyung
                EventTime = DateTime.Now,
57 b79d6e7f humkyung
                MarkupDataColl = new List<UndoData>(),
58 d128ceb2 humkyung
            };
59
60
            foreach (var comment in comments)
61
            {
62 34ac8db7 humkyung
                UndoData _UndoData = new UndoData()
63
                {
64
                    Markup = comment
65
                };
66 f258d884 humkyung
                _UndoData.Clone = comment.Clone();
67
                UndoData.MarkupDataColl.Add(_UndoData);
68 34ac8db7 humkyung
69
                if (_EventType == EventType.Delete)
70
                {
71
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(comment);
72
                    ViewerDataModel.Instance.MarkupControls.Remove(comment);
73
74
                    var Item_ = ViewerDataModel.Instance.MyMarkupList.Find(d => d.ID == comment.CommentID);
75
                    ViewerDataModel.Instance.MyMarkupList.Remove(Item_);
76
77
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
78
                        null, EventType.Delete, MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID).CommentID, null);
79
                }
80
                else
81
                {
82
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
83
                        MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID), EventType.Operation, null, null);
84
                }
85 d128ceb2 humkyung
            }
86 34ac8db7 humkyung
87
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo).ToList().ForEach(i =>
88 d128ceb2 humkyung
            {
89
                ViewerDataModel.Instance.UndoDataList.Remove(i);
90
            });
91 e5bd2147 swate0609
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
92 d128ceb2 humkyung
        }
93 f816dd63 humkyung
94
        /// <summary>
95 f258d884 humkyung
        /// undo 실행
96 f816dd63 humkyung
        /// </summary>
97
        public void Execute()
98
        {
99
            AdornerFinal final;
100
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
101
102 34ac8db7 humkyung
            UndoDataGroup undo = ViewerDataModel.Instance.UndoDataList.Where(data => !data.IsUndo).ToList()
103 ab7fe8c0 humkyung
                .OrderByDescending(order => order.EventTime).FirstOrDefault();
104 f816dd63 humkyung
            if (undo == null) return;
105
106
            switch (undo.Event)
107
            {
108 873011c4 humkyung
                case (EventType.Create):
109 f816dd63 humkyung
                    {
110 873011c4 humkyung
                        foreach (var item in undo.MarkupDataColl)
111 f816dd63 humkyung
                        {
112
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
113 34ac8db7 humkyung
114 39f0624f ljiyeon
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
115 873011c4 humkyung
                            null, EventType.Delete, item.Markup.CommentID, null);
116 f816dd63 humkyung
                        }
117
                    }
118
                    break;
119 873011c4 humkyung
                case (EventType.Delete):
120 f816dd63 humkyung
                    {
121 85132173 humkyung
                        List<CommentUserInfo> comments = new List<CommentUserInfo>();
122 873011c4 humkyung
                        foreach (var item in undo.MarkupDataColl)
123 f816dd63 humkyung
                        {
124 8e6884a5 taeseongkim
                            item.Markup.Load();
125 34ac8db7 humkyung
                            item.Markup.UpdateControl();
126 85132173 humkyung
                            comments.Add(item.Markup);
127 f816dd63 humkyung
                        }
128 34ac8db7 humkyung
129 85132173 humkyung
                        var adorner = new AdornerFinal(comments);
130
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adorner);
131
                        ///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
132 f816dd63 humkyung
                    }
133
                    break;
134 873011c4 humkyung
                case (EventType.Operation):
135 f816dd63 humkyung
                    {
136
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
137
138 873011c4 humkyung
                        foreach (var item in undo.MarkupDataColl)
139 f816dd63 humkyung
                        {
140 86143026 humkyung
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
141 cbeff740 swate0609
142 86143026 humkyung
                            var tmp = item.Markup.Clone();
143
                            item.Markup.Copy(item.Clone);
144
                            item.Clone.Copy(tmp);
145
                            item.Markup.UpdateControl();
146 f816dd63 humkyung
147
                            comment.Add(item.Markup);
148
                        }
149 85132173 humkyung
                        var adoner = new AdornerFinal(comment);
150
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adoner);
151 34ac8db7 humkyung
                        ///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
152 f816dd63 humkyung
                    }
153
                    break;
154
            }
155 34ac8db7 humkyung
156 ab7fe8c0 humkyung
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList()
157
                .OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
158 f816dd63 humkyung
            {
159
                i.IsUndo = true;
160
            });
161
        }
162 d128ceb2 humkyung
    }
163
}
클립보드 이미지 추가 (최대 크기: 500 MB)