프로젝트

일반

사용자정보

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

markus / KCOM / Events / UndoCommand.cs @ 74abcf6f

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

1
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
using KCOM.Controls;
18
using MarkupToPDF.Controls.Parsing;
19

    
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
        /// <date>2019.06.14</date>
49
        /// <param name="comments"></param>
50
        public void Push(ICollection<CommentUserInfo> comments, double dAngle)
51
        {
52
            List<Point> p_set = new List<Point>();
53

    
54
            Undo_data UndoData = new Undo_data()
55
            {
56
                IsUndo = false,
57
                Event = Event_Type.Thumb,
58
                EventTime = DateTime.Now,
59
                Markup_List = new List<Multi_Undo_data>(),
60
            };
61

    
62
            Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
63

    
64
            foreach (var comment in comments)
65
            {
66
                multi_Undo_Data.PointSet = new List<Point>();
67
                p_set = new List<Point>();
68

    
69
                if (comment is TextControl)
70
                {
71
                    multi_Undo_Data.PointSet.Add((comment as TextControl).StartPoint);
72
                    multi_Undo_Data.PointSet.Add((comment as TextControl).EndPoint);
73
                }
74

    
75
                foreach (var point in (comment as IPath).PointSet)
76
                {
77
                    multi_Undo_Data.PointSet.Add(point);
78
                }
79

    
80
                if (comment is ArrowTextControl)
81
                {
82
                    multi_Undo_Data.Angle = dAngle = (comment as ArrowTextControl).CommentAngle;
83
                }
84
                else
85
                {
86
                    multi_Undo_Data.Angle = dAngle;
87
                }
88

    
89
                multi_Undo_Data.Markup = comment;
90
                UndoData.Markup_List.Add(multi_Undo_Data);
91
                ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
92
                            MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Thumb, null, null);
93

    
94
                multi_Undo_Data = new Multi_Undo_data();                
95
            }
96
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
97
            {
98
                ViewerDataModel.Instance.UndoDataList.Remove(i);
99
            });
100

    
101
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);            
102
        }
103

    
104
        /// <summary>
105
        /// undo
106
        /// </summary>
107
        public void Execute()
108
        {
109
            AdornerFinal final;
110
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
111

    
112
            Undo_data undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList().OrderByDescending(order => order.EventTime).FirstOrDefault();
113
            if (undo == null) return;
114

    
115
            switch (undo.Event)
116
            {
117
                case (Event_Type.Create):
118
                    {
119
                        foreach (var item in undo.Markup_List)
120
                        {
121
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
122
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
123
                            null, Event_Type.Delete, item.Markup.CommentID, null);
124
                        }
125
                    }
126
                    break;
127
                case (Event_Type.Delete):
128
                    {
129
                        foreach (var item in undo.Markup_List)
130
                        {
131
                            //var markupitem = MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID);
132

    
133
                            //if (markupitem != null)
134
                            //{
135
                            //    IKCOM.MarkupItemEx markup = new IKCOM.MarkupItemEx
136
                            //    {
137
                            //        Data = markupitem.ConvertData,
138
                            //        Data_Type = markupitem.DATA_TYPE,
139
                            //        ID = markupitem.CommentID,
140
                            //        IsUpdate = false,
141
                            //        MarkupInfoID = App.Custom_ViewInfoId,
142
                            //        PageNumber = ViewerDataModel.Instance.PageNumber,
143
                            //        //Symbol_ID = p.Symbol_ID,
144
                            //        //Group_ID = p.Group_ID
145
                            //    };
146

    
147
                            //    ViewerDataModel.Instance.MyMarkupList.Add(markup);
148
                            //}
149

    
150
                            //ViewerDataModel.Instance.MarkupControls.Add(item.Markup);
151
                            item.Markup.Load();
152

    
153
                            ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup);
154
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
155
                            MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
156
                        }
157
                    }
158
                    break;
159
                case (Event_Type.Thumb):
160
                    {
161
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
162

    
163
                        foreach (var item in undo.Markup_List)
164
                        {
165
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
166

    
167
                            if ((item.Markup as IViewBox) != null)
168
                            {
169
                                (item.Markup as IViewBox).CommentAngle = item.Angle;
170
                            }
171
                            if ((item.Markup as TextControl) != null)
172
                            {
173
                                (item.Markup as TextControl).CommentAngle = item.Angle;
174
                                Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X);
175
                                Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y);
176
                            }
177
                            else
178
                            {
179
                                (item.Markup as IPath).PointSet = item.PointSet;
180
                                (item.Markup as CommentUserInfo).UpdateControl();
181
                            }
182

    
183
                            comment.Add(item.Markup);
184
                        }
185
                        final = new AdornerFinal(comment);
186
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
187
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
188
                    }
189
                    break;
190
                case (Event_Type.Select):
191
                    {
192
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
193

    
194
                        foreach (var item in undo.Markup_List)
195
                        {
196
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
197

    
198
                            if ((item.Markup as IPath) != null)
199
                            {
200
                                (item.Markup as IPath).LineSize = item.LineSize;
201
                            }
202
                            if ((item.Markup as UIElement) != null)
203
                            {
204
                                (item.Markup as UIElement).Opacity = item.Opacity;
205
                            }
206
                            if ((item.Markup as IDashControl) != null)
207
                            {
208
                                (item.Markup as IDashControl).DashSize = item.DashSize;
209
                            }
210
                            if ((item.Markup as IShapeControl) != null)
211
                            {
212
                                (item.Markup as IShapeControl).Paint = item.paint;
213
                            }
214

    
215
                            comment.Add(item.Markup);
216
                        }
217

    
218
                        final = new AdornerFinal(comment);
219
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
220
                    }
221
                    break;
222
                case (Event_Type.Option):
223
                    {
224
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
225

    
226
                        foreach (var item in undo.Markup_List)
227
                        {
228
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
229

    
230
                            if (undo.LineSize != 0 && item.Markup as IPath != null)
231
                            {
232
                                (item.Markup as IPath).LineSize = undo.LineSize;
233
                            }
234
                            else if (undo.Opacity != 0 && item.Markup as UIElement != null)
235
                            {
236
                                (item.Markup as UIElement).Opacity = undo.Opacity;
237
                            }
238
                            else if (undo.DashSize != null && item.Markup as IDashControl != null)
239
                            {
240
                                (item.Markup as IDashControl).DashSize = undo.DashSize;
241
                            }
242
                            else if (undo.Interval != 0 && item.Markup as LineControl != null)
243
                            {
244
                                (item.Markup as LineControl).Interval = undo.Interval;
245
                            }
246
                            else if (item.Markup as IShapeControl != null)
247
                            {
248
                                (item.Markup as IShapeControl).Paint = undo.paint;
249
                            }
250
                            comment.Add(item.Markup);
251
                        }
252
                        final = new AdornerFinal(comment);
253
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
254
                    }
255
                    break;
256
            }
257
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList().OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
258
            {
259
                i.IsUndo = true;
260
            });
261
        }
262
    }
263
}
클립보드 이미지 추가 (최대 크기: 500 MB)