프로젝트

일반

사용자정보

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

markus / KCOM / Events / UndoCommand.cs @ 873011c4

이력 | 보기 | 이력해설 | 다운로드 (13.8 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, double dBeforeAngle = 0.0, List<Point> lstBeforePointSet = null)
51
        //{
52
        //    UndoData UndoData = new UndoData()
53
        //    {
54
        //        IsUndo = false,
55
        //        Event = EventType.Thumb,
56
        //        EventTime = DateTime.Now,
57
        //        MarkupDataColl = new List<Multi_UndoData>(),
58
        //    };
59

    
60
        //    Multi_UndoData multi_UndoData = new Multi_UndoData();
61

    
62
        //    foreach (var comment in comments)
63
        //    {
64
        //        multi_UndoData.PointSet = new List<Point>();
65
        //        var p_set = new List<Point>();
66

    
67
        //        if (comment is TextControl)
68
        //        {
69
        //            multi_UndoData.PointSet.Add((comment as TextControl).StartPoint);
70
        //            multi_UndoData.PointSet.Add((comment as TextControl).EndPoint);
71
        //        }
72

    
73
        //        foreach (var point in (comment as IPath).PointSet)
74
        //        {
75
        //            multi_UndoData.PointSet.Add(point);
76
        //        }
77

    
78
        //        if (lstBeforePointSet != null)
79
        //            multi_UndoData.BeforePointSet = lstBeforePointSet;
80

    
81
        //        if (comment is ArrowTextControl)
82
        //        {
83
        //            //multi_UndoData.Angle = dAngle = (comment as ArrowTextControl).CommentAngle;
84
        //            multi_UndoData.Angle = dAngle;
85
        //            multi_UndoData.BeforeAngle = dBeforeAngle;
86
        //        }
87
        //        else
88
        //        {
89
        //            multi_UndoData.Angle = dAngle;
90
        //            multi_UndoData.BeforeAngle = dBeforeAngle;
91
        //        }
92

    
93
        //        multi_UndoData.Markup = comment;
94
        //        UndoData.MarkupDataColl.Add(multi_UndoData);
95
        //        ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
96
        //                    MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Thumb, null, null);
97

    
98
        //        multi_UndoData = new Multi_UndoData();                
99
        //    }
100
        //    ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
101
        //    {
102
        //        ViewerDataModel.Instance.UndoDataList.Remove(i);
103
        //    });
104

    
105
        //    ViewerDataModel.Instance.UndoDataList.Add(UndoData);            
106
        //}
107

    
108
        public void Push(ICollection<CommentUserInfo> comments)
109
        {
110
            UndoDataGroup UndoData = new UndoDataGroup()
111
            {
112
                IsUndo = false,
113
                Event = EventType.Operation,
114
                EventTime = DateTime.Now,
115
                MarkupDataColl = new List<Multi_UndoData>(),
116
            };
117

    
118
            foreach (var comment in comments)
119
            {
120
                Multi_UndoData multi_UndoData = new Multi_UndoData();
121
                multi_UndoData.Markup = comment;
122
                multi_UndoData.Clone = comment.Clone();
123
                /*
124
                multi_UndoData.PointSet = new List<Point>();
125
                var p_set = new List<Point>();
126

    
127
                if (comment is TextControl)
128
                {
129
                    multi_UndoData.PointSet.Add((comment as TextControl).StartPoint);
130
                    multi_UndoData.PointSet.Add((comment as TextControl).EndPoint);
131
                }
132

    
133
                foreach (var point in (comment as IPath).PointSet)
134
                {
135
                    multi_UndoData.PointSet.Add(point);
136
                }
137

    
138

    
139
                List<Point> points = new List<Point>();
140
                foreach(var point in (comment as IPath).PointSet)
141
                {
142
                    points.Add(point);
143
                }
144
                multi_UndoData.PointSet = points;
145

    
146
                if (comment is ArrowTextControl)
147
                {
148
                    //multi_UndoData.Angle = dAngle = (comment as ArrowTextControl).CommentAngle;
149
                    multi_UndoData.Angle = comment.CommentAngle;
150
                }
151
                else
152
                {
153
                    multi_UndoData.Angle = comment.CommentAngle;
154
                }
155

    
156
                multi_UndoData.Markup = comment;
157
                */
158
                UndoData.MarkupDataColl.Add(multi_UndoData);
159
                ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
160
                            MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Operation, null, null);
161
            }
162
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
163
            {
164
                ViewerDataModel.Instance.UndoDataList.Remove(i);
165
            });
166

    
167
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
168
        }
169

    
170
        /// <summary>
171
        /// undo
172
        /// </summary>
173
        public void Execute()
174
        {
175
            AdornerFinal final;
176
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
177

    
178
            UndoDataGroup undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList()
179
                .OrderByDescending(order => order.EventTime).FirstOrDefault();
180
            if (undo == null) return;
181

    
182
            switch (undo.Event)
183
            {
184
                case (EventType.Create):
185
                    {
186
                        foreach (var item in undo.MarkupDataColl)
187
                        {
188
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
189
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
190
                            null, EventType.Delete, item.Markup.CommentID, null);
191
                        }
192
                    }
193
                    break;
194
                case (EventType.Delete):
195
                    {
196
                        foreach (var item in undo.MarkupDataColl)
197
                        {
198
                            //var markupitem = MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID);
199

    
200
                            //if (markupitem != null)
201
                            //{
202
                            //    IKCOM.MarkupItemEx markup = new IKCOM.MarkupItemEx
203
                            //    {
204
                            //        Data = markupitem.ConvertData,
205
                            //        Data_Type = markupitem.DATA_TYPE,
206
                            //        ID = markupitem.CommentID,
207
                            //        IsUpdate = false,
208
                            //        MarkupInfoID = App.Custom_ViewInfoId,
209
                            //        PageNumber = ViewerDataModel.Instance.PageNumber,
210
                            //        //Symbol_ID = p.Symbol_ID,
211
                            //        //Group_ID = p.Group_ID
212
                            //    };
213

    
214
                            //    ViewerDataModel.Instance.MyMarkupList.Add(markup);
215
                            //}
216

    
217
                            //ViewerDataModel.Instance.MarkupControls.Add(item.Markup);
218
                            item.Markup.Load();
219

    
220
                            ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup);
221
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
222
                            MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
223
                        }
224
                    }
225
                    break;
226
                case (EventType.Operation):
227
                    {
228
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
229

    
230
                        foreach (var item in undo.MarkupDataColl)
231
                        {
232
                            double dOriAngle = 0.0;
233
                            List<Point> lstOriPointSet = new List<Point>();
234

    
235
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
236

    
237
                            if ((item.Markup as IViewBox) != null)
238
                            {
239
                                dOriAngle = (item.Markup as IViewBox).CommentAngle;
240
                                (item.Markup as IViewBox).CommentAngle = item.Angle;
241
                                item.Angle = dOriAngle;
242
                            }
243
                            else
244
                            {
245
                                ///(item.Markup).CommentAngle = item.Angle;
246
                                ///(item.Markup as IPath).PointSet = item.PointSet;
247
                                ///(item.Markup as IPath).PointSet = item.BeforePointSet != null ? item.BeforePointSet : new List<Point>();
248
                                item.Markup.Copy(item.Clone);
249
                                (item.Markup as CommentUserInfo).UpdateControl();
250
                            }
251

    
252
                            comment.Add(item.Markup);
253
                        }
254
                        final = new AdornerFinal(comment);
255
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
256
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
257
                    }
258
                    break;
259
                    /*
260
                case (EventType.Select):
261
                    {
262
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
263

    
264
                        foreach (var item in undo.MarkupDataColl)
265
                        {
266
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
267

    
268
                            if ((item.Markup as IPath) != null)
269
                            {
270
                                (item.Markup as IPath).LineSize = item.LineSize;
271
                            }
272
                            if ((item.Markup as UIElement) != null)
273
                            {
274
                                (item.Markup as UIElement).Opacity = item.Opacity;
275
                            }
276
                            if ((item.Markup as IDashControl) != null)
277
                            {
278
                                (item.Markup as IDashControl).DashSize = item.DashSize;
279
                            }
280
                            if ((item.Markup as IShapeControl) != null)
281
                            {
282
                                (item.Markup as IShapeControl).Paint = item.paint;
283
                            }
284

    
285
                            comment.Add(item.Markup);
286
                        }
287

    
288
                        final = new AdornerFinal(comment);
289
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
290
                    }
291
                    break;
292
                case (EventType.Option):
293
                    {
294
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
295

    
296
                        foreach (var item in undo.MarkupDataColl)
297
                        {
298
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
299

    
300
                            if (undo.LineSize != 0 && item.Markup as IPath != null)
301
                            {
302
                                (item.Markup as IPath).LineSize = undo.LineSize;
303
                            }
304
                            else if (undo.Opacity != 0 && item.Markup as UIElement != null)
305
                            {
306
                                (item.Markup as UIElement).Opacity = undo.Opacity;
307
                            }
308
                            else if (undo.DashSize != null && item.Markup as IDashControl != null)
309
                            {
310
                                (item.Markup as IDashControl).DashSize = undo.DashSize;
311
                            }
312
                            else if (undo.Interval != 0 && item.Markup as LineControl != null)
313
                            {
314
                                (item.Markup as LineControl).Interval = undo.Interval;
315
                            }
316
                            else if (item.Markup as IShapeControl != null)
317
                            {
318
                                (item.Markup as IShapeControl).Paint = undo.paint;
319
                            }
320
                            comment.Add(item.Markup);
321
                        }
322
                        final = new AdornerFinal(comment);
323
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
324
                    }
325
                    break;
326
                    */
327
            }
328
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList()
329
                .OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
330
            {
331
                i.IsUndo = true;
332
            });
333
        }
334
    }
335
}
클립보드 이미지 추가 (최대 크기: 500 MB)